diff --git a/includes/embeds/class-amp-dailymotion-embed.php b/includes/embeds/class-amp-dailymotion-embed.php index 19db158f8db..d06f937066f 100644 --- a/includes/embeds/class-amp-dailymotion-embed.php +++ b/includes/embeds/class-amp-dailymotion-embed.php @@ -150,7 +150,7 @@ public function render( $args ) { * @return integer Video ID. */ private function get_video_id_from_url( $url ) { - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); parse_str( $parsed_url['path'], $path ); $tok = explode( '/', $parsed_url['path'] ); $tok = explode( '_', $tok[2] ); diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index bc2a5b83abe..c0c00616e81 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -178,7 +178,7 @@ private function render_embed_fallback( $url ) { * @return string Track ID or empty string if none matched. */ private function get_track_id_from_url( $url ) { - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); if ( ! preg_match( '#tracks/(?P[^/]+)#', $parsed_url['path'], $matches ) ) { return ''; } diff --git a/includes/embeds/class-amp-vimeo-embed.php b/includes/embeds/class-amp-vimeo-embed.php index f475b894e48..04849fea4ac 100644 --- a/includes/embeds/class-amp-vimeo-embed.php +++ b/includes/embeds/class-amp-vimeo-embed.php @@ -156,7 +156,7 @@ public function render( $args ) { * @return integer Video ID. */ private function get_video_id_from_url( $url ) { - $parsed_url = parse_url( $url ); + $parsed_url = wp_parse_url( $url ); parse_str( $parsed_url['path'], $path ); $video_id = ''; diff --git a/includes/embeds/class-amp-youtube-embed.php b/includes/embeds/class-amp-youtube-embed.php index d8d5bc2d6c2..98a72054d3c 100644 --- a/includes/embeds/class-amp-youtube-embed.php +++ b/includes/embeds/class-amp-youtube-embed.php @@ -149,7 +149,7 @@ public function render( $args ) { */ private function get_video_id_from_url( $url ) { $video_id = false; - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); if ( self::SHORT_URL_HOST === substr( $parsed_url['host'], -strlen( self::SHORT_URL_HOST ) ) ) { /* youtu.be/{id} */ diff --git a/includes/sanitizers/class-amp-img-sanitizer.php b/includes/sanitizers/class-amp-img-sanitizer.php index 86fe45e2770..5a9bd2f5d7c 100644 --- a/includes/sanitizers/class-amp-img-sanitizer.php +++ b/includes/sanitizers/class-amp-img-sanitizer.php @@ -227,7 +227,7 @@ private function adjust_and_replace_node( $node ) { */ private function is_gif_url( $url ) { $ext = self::$anim_extension; - $path = AMP_WP_Utils::parse_url( $url, PHP_URL_PATH ); + $path = wp_parse_url( $url, PHP_URL_PATH ); return substr( $path, -strlen( $ext ) ) === $ext; } } diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index 2f884c14b27..9ac261bb9ae 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -1216,7 +1216,7 @@ private function check_attr_spec_rule_allowed_protocol( $node, $attr_name, $attr * This seems to be an acceptable check since the AMP validator * will allow a URL with no protocol to pass validation. */ - $url_scheme = AMP_WP_Utils::parse_url( $url, PHP_URL_SCHEME ); + $url_scheme = wp_parse_url( $url, PHP_URL_SCHEME ); if ( $url_scheme ) { if ( ! in_array( strtolower( $url_scheme ), $attr_spec_rule[ AMP_Rule_Spec::VALUE_URL ][ AMP_Rule_Spec::ALLOWED_PROTOCOL ], true ) ) { return AMP_Rule_Spec::FAIL; @@ -1233,7 +1233,7 @@ private function check_attr_spec_rule_allowed_protocol( $node, $attr_name, $attr * This seems to be an acceptable check since the AMP validator * will allow a URL with no protocol to pass validation. */ - $url_scheme = AMP_WP_Utils::parse_url( $url, PHP_URL_SCHEME ); + $url_scheme = wp_parse_url( $url, PHP_URL_SCHEME ); if ( $url_scheme ) { if ( ! in_array( strtolower( $url_scheme ), $attr_spec_rule[ AMP_Rule_Spec::VALUE_URL ][ AMP_Rule_Spec::ALLOWED_PROTOCOL ], true ) ) { return AMP_Rule_Spec::FAIL; @@ -1266,7 +1266,7 @@ private function check_attr_spec_rule_disallowed_relative( $node, $attr_name, $a if ( $node->hasAttribute( $attr_name ) ) { $urls_to_test = preg_split( '/\s*,\s*/', $node->getAttribute( $attr_name ) ); foreach ( $urls_to_test as $url ) { - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); /* * The JS AMP validator seems to consider 'relative' to mean @@ -1285,7 +1285,7 @@ private function check_attr_spec_rule_disallowed_relative( $node, $attr_name, $a if ( $node->hasAttribute( $alternative_name ) ) { $urls_to_test = preg_split( '/\s*,\s*/', $node->getAttribute( $alternative_name ) ); foreach ( $urls_to_test as $url ) { - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); if ( empty( $parsed_url['scheme'] ) ) { return AMP_Rule_Spec::FAIL; } @@ -1338,7 +1338,7 @@ private function check_attr_spec_rule_disallowed_empty( $node, $attr_name, $attr private function check_attr_spec_rule_disallowed_domain( $node, $attr_name, $attr_spec_rule ) { if ( isset( $attr_spec_rule[ AMP_Rule_Spec::DISALLOWED_DOMAIN ] ) && $node->hasAttribute( $attr_name ) ) { $attr_value = $node->getAttribute( $attr_name ); - $url_domain = AMP_WP_Utils::parse_url( $attr_value, PHP_URL_HOST ); + $url_domain = wp_parse_url( $attr_value, PHP_URL_HOST ); if ( ! empty( $url_domain ) ) { foreach ( $attr_spec_rule[ AMP_Rule_Spec::DISALLOWED_DOMAIN ] as $disallowed_domain ) { if ( strtolower( $url_domain ) === strtolower( $disallowed_domain ) ) { diff --git a/includes/utils/class-amp-image-dimension-extractor.php b/includes/utils/class-amp-image-dimension-extractor.php index a67f04099e5..057f4105f38 100644 --- a/includes/utils/class-amp-image-dimension-extractor.php +++ b/includes/utils/class-amp-image-dimension-extractor.php @@ -51,7 +51,7 @@ public static function normalize_url( $url ) { return set_url_scheme( $url, 'http' ); } - $parsed = AMP_WP_Utils::parse_url( $url ); + $parsed = wp_parse_url( $url ); if ( ! isset( $parsed['host'] ) ) { $path = ''; if ( isset( $parsed['path'] ) ) { diff --git a/includes/utils/class-amp-wp-utils.php b/includes/utils/class-amp-wp-utils.php index bacb72458af..924b6a3cdbd 100644 --- a/includes/utils/class-amp-wp-utils.php +++ b/includes/utils/class-amp-wp-utils.php @@ -1,15 +1,39 @@ get_queried_object_id(); diff --git a/tests/test-amp-wp-utils.php b/tests/test-amp-wp-utils.php deleted file mode 100644 index 5ab5d1277ec..00000000000 --- a/tests/test-amp-wp-utils.php +++ /dev/null @@ -1,69 +0,0 @@ - array( - 'https://example.com/path', - array( - 'scheme' => 'https', - 'host' => 'example.com', - 'path' => '/path', - ), - -1, - ), - - 'valid__with_component' => array( - 'https://example.com/path', - 'example.com', - PHP_URL_HOST, - ), - - 'valid__schemaless__no_component' => array( - '//example.com/path', - array( - 'host' => 'example.com', - 'path' => '/path', - ), - -1, - ), - - 'valid__schemaless__with_component' => array( - '//example.com/path', - 'example.com', - PHP_URL_HOST, - ), - ); - } - - /** - * Test URL parsing. - * - * @param string $url The URL. - * @param string $expected Expected value. - * @param string $component Derived value. - * - * @dataProvider get_test_data - */ - public function test__method( $url, $expected, $component ) { - $actual = AMP_WP_Utils::parse_url( $url, $component ); - - $this->assertEquals( $expected, $actual ); - } -} diff --git a/wpcom-helper.php b/wpcom-helper.php index 37af6a9ee91..eddc6ef2890 100644 --- a/wpcom-helper.php +++ b/wpcom-helper.php @@ -129,12 +129,12 @@ function wpcom_amp_extract_image_dimensions_from_querystring( $dimensions ) { continue; } - $host = parse_url( $url, PHP_URL_HOST ); + $host = wp_parse_url( $url, PHP_URL_HOST ); if ( ! wp_endswith( $host, '.wp.com' ) || ! wp_endswith( $host, '.files.wordpress.com' ) ) { continue; } - parse_str( parse_url( $url, PHP_URL_QUERY ), $query ); + parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $query ); $w = isset( $query['w'] ) ? absint( $query['w'] ) : false; $h = isset( $query['h'] ) ? absint( $query['h'] ) : false;