Skip to content

Loading…

Issue #736: Fix Alexa ID string validation #757

Merged
merged 1 commit into from

2 participants

@jrfnl

And further code abstraction/simplification or the verification string validations including nice error messages

@jrfnl jrfnl Issue #736: Fix Alexa ID string validation
And further code abstraction/simplification or the verification string validations including nice error messages
e4c406c
@jrfnl jrfnl added bug admin labels
@barrykooij barrykooij merged commit e4c406c into Yoast:master

1 check passed

Details default The Travis CI build passed
@jrfnl jrfnl deleted the jrfnl:Issue-736-AlexaID-validation branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2014
  1. @jrfnl

    Issue #736: Fix Alexa ID string validation

    jrfnl committed
    And further code abstraction/simplification or the verification string validations including nice error messages
Showing with 34 additions and 32 deletions.
  1. +33 −32 inc/class-wpseo-options.php
  2. +1 −0 readme.txt
View
65 inc/class-wpseo-options.php
@@ -792,6 +792,7 @@ protected function validate_option( $dirty, $clean, $old ) {
if ( isset( $dirty[$key] ) && $dirty[$key] !== '' ) {
$meta = $dirty[$key];
if ( strpos( $meta, 'content=' ) ) {
+ // Make sure we only have the real key, not a complete meta tag
preg_match( '`content=([\'"])([^\'"]+)\1`', $meta, $match );
if ( isset( $match[2] ) ) {
$meta = $match[2];
@@ -801,49 +802,49 @@ protected function validate_option( $dirty, $clean, $old ) {
$meta = sanitize_text_field( $meta );
if ( $meta !== '' ) {
+ $regex = '`^[A-Fa-f0-9_-]+$`';
+ $service = '';
+
switch ( $key ) {
case 'googleverify':
- if ( preg_match( '`^[A-Za-z0-9_-]+$`', $meta ) ) {
- $clean[$key] = $meta;
- } else {
- if ( isset( $old[$key] ) && preg_match( '`^[A-Za-z0-9_-]+$`', $old[$key] ) ) {
- $clean[$key] = $old[$key];
- }
- if ( function_exists( 'add_settings_error' ) ) {
- add_settings_error(
- $this->group_name, // slug title of the setting
- '_' . $key, // suffix-id for the error message box
- sprintf( __( '%s does not seem to be a valid Google Webmaster Tools Verification string. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $meta ) . '</strong>' ), // the error message
- 'error' // error type, either 'error' or 'updated'
- );
- }
- }
+ $regex = '`^[A-Za-z0-9_-]+$`';
+ $service = 'Google Webmaster tools';
break;
case 'msverify':
+ $service = 'Bing Webmaster tools';
+ break;
+
case 'pinterestverify':
+ $service = 'Pinterest';
+ break;
+
case 'yandexverify':
- case 'alexaverify':
- if ( preg_match( '`^[A-Fa-f0-9_-]+$`', $meta ) ) {
- $clean[$key] = $meta;
- } else {
- if ( isset( $old[$key] ) && preg_match( '`^[A-Fa-f0-9_-]+$`', $old[$key] ) ) {
- $clean[$key] = $old[$key];
- }
- if ( function_exists( 'add_settings_error' ) ) {
- add_settings_error(
- $this->group_name, // slug title of the setting
- '_' . $key, // suffix-id for the error message box
- sprintf( __( '%s does not seem to be a valid %s verification string. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $meta ) . '</strong>', $key ), // the error message
- 'error' // error type, either 'error' or 'updated'
- );
- }
- }
+ $service = 'Yandex Webmaster tools';
break;
+ case 'alexaverify':
+ $regex = '`^[A-Za-z0-9]{20,}$`';
+ $service = 'Alexa ID';
+ }
+
+ if ( preg_match( $regex, $meta ) ) {
+ $clean[$key] = $meta;
+ } else {
+ if ( isset( $old[$key] ) && preg_match( $regex, $old[$key] ) ) {
+ $clean[$key] = $old[$key];
+ }
+ if ( function_exists( 'add_settings_error' ) ) {
+ add_settings_error(
+ $this->group_name, // slug title of the setting
+ '_' . $key, // suffix-id for the error message box
+ sprintf( __( '%s does not seem to be a valid %s verification string. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $meta ) . '</strong>', $service ), // the error message
+ 'error' // error type, either 'error' or 'updated'
+ );
+ }
}
}
- unset( $meta );
+ unset( $meta, $regex, $service );
}
break;
View
1 readme.txt
@@ -118,6 +118,7 @@ You'll find the [FAQ on Yoast.com](https://yoast.com/wordpress/plugins/seo/faq/)
* Potentially fix [issue 565](https://github.com/Yoast/wordpress-seo/issues/565) bbpress warning message. Thanks [inetbiz](https://github.com/inetbiz) for reporting and [tobylewis](https://github.com/tobylewis) for finding the likely cause.
* Filter 'wpseo_pre_analysis_post_content' output is now only loaded in DOM object if not empty.
* $post_content is now unset after loading in DOM object.
+ * Fix Alexa ID string validation, as reported by [kyasajin](https://github.com/kyasajin) and [Bubichka](https://github.com/Bubichka) in [issue 736](https://github.com/Yoast/wordpress-seo/issues/736) - props [Jrf](http://profiles.wordpress.org/jrf).
* Enhancements
* Twitter metatag key is now filterable by 'wpseo_twitter_metatag_key'
Something went wrong with that request. Please try again.