Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preg_match error sanitizer #1154

Closed
nickreale opened this issue May 17, 2018 · 9 comments
Closed

preg_match error sanitizer #1154

nickreale opened this issue May 17, 2018 · 9 comments

Comments

@nickreale
Copy link

nickreale commented May 17, 2018

I installed the plugin on several sites. I only seem to have an issue with one site where every amp post is giving this error.

Warning: preg_match() expects parameter 2 to be string, array given in /home/molloy6/public_html/familytireandautoservice.com/wp-content/plugins/amp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php on line 1179

Here is a link
http://www.familytireandautoservice.com/locations/tires-needed-denver-tires/amp/

I have several hundred posts and it has this error on all I have checked.

Any ideas or help is appreciated.

@nickreale
Copy link
Author

nickreale commented May 17, 2018

private function check_attr_spec_rule_valid_url( $node, $attr_name, $attr_spec_rule ) {
		if ( isset( $attr_spec_rule[ AMP_Rule_Spec::VALUE_URL ] ) ) {
			if ( $node->hasAttribute( $attr_name ) ) {
				$urls_to_test = preg_split( '/\s*,\s*/', $node->getAttribute( $attr_name ) );
				foreach ( $urls_to_test as $url ) {
					$url = urldecode( $url );
					// Check if the host contains invalid chars.
					$url_host = wp_parse_url( $url, PHP_URL_HOST );
					if ( $url_host && preg_match( '/[!"#$%&\'()*+,\/:;<=>?@[\]^`{|}~\s]/i', $url_host ) ) {
						return AMP_Rule_Spec::FAIL;
					}

					// Check if the protocol contains invalid chars.
					$dots_pos = strpos( $url, ':' );
					if ( false !== $dots_pos && preg_match( '/[!"#$%&\'()*+,\/:;<=>?@[\]^`{|}~\s]/i', substr( $url, 0, $dots_pos ) ) ) {
						return AMP_Rule_Spec::FAIL;
					}
				}

				return AMP_Rule_Spec::PASS;
			}
		}

		return AMP_Rule_Spec::NOT_APPLICABLE;
	}

@westonruter
Copy link
Member

@nickreale What version of WordPress PHP are you running? What appears to be happening is on this line:

https://github.com/Automattic/amp-wp/blob/5ab7f0840a2b0735e6e982b8d3a3c4376d449075/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php#L1178

The PHP_URL_HOST param is not being recognized. This second $component param was introduced in WordPress 4.7. Are you using an older version of WordPress? Notice that the plugin requires at least WordPress 4.7:

https://github.com/Automattic/amp-wp/blob/5ab7f0840a2b0735e6e982b8d3a3c4376d449075/readme.txt#L4-L5

@nickreale
Copy link
Author

I am using the latest version.

@nickreale
Copy link
Author

4.9.6

@westonruter
Copy link
Member

I'm confused. If this is the code in question:

$url = urldecode( $url );
// Check if the host contains invalid chars.
$url_host = wp_parse_url( $url, PHP_URL_HOST );
if ( $url_host && preg_match( '/[!"#$%&\'()*+,\/:;<=>?@[\]^`{|}~\s]/i', $url_host ) ) {

The urldecode() function returns a string, and wp_parse_url() would return a string here. So I don't see how $url_host could be anything other than a string.

@nickreale
Copy link
Author

nickreale commented May 19, 2018 via email

@westonruter
Copy link
Member

twentyseventeen_get_svg() is undefined? It seems you have a deeper problem with your install. Maybe a problem with CherryFramework?

@nickreale
Copy link
Author

nickreale commented May 19, 2018 via email

@westonruter
Copy link
Member

By best guess is it is a problem with CherryFramework, so I'm going to close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants