Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/test-tool-update-site-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ function () use ( $state_time ) {
'local URL' => array( 'http://localhost:8080/wordpress/', 'http://localhost:8080/wordpress' ),
'private IPv4 URL' => array( 'http://192.168.1.20:8080', 'http://192.168.1.20:8080' ),
'IPv6 URL' => array( 'https://[::1]:8443/wp', 'https://[::1]:8443/wp' ),
'Unicode path' => array( 'https://example.com/路径', 'https://example.com/路径' ),
'maximum length' => array( $max_length_url, $max_length_url ),
);
foreach ( $valid_urls as $label => $case ) {
Expand All @@ -246,6 +247,12 @@ function () use ( $state_time ) {
'internal whitespace' => 'https://example.com/a b',
'leading whitespace' => ' https://example.com',
'trailing whitespace' => "https://example.com\n",
'non-breaking space' => "https://example.com/a\u{00A0}b",
'next-line whitespace' => "https://example.com/a\u{0085}b",
'em space' => "https://example.com/a\u{2003}b",
'line separator' => "https://example.com/a\u{2028}b",
'paragraph separator' => "https://example.com/a\u{2029}b",
'invalid UTF-8' => "https://example.com/\xC3\x28",
'backslash' => 'https://example.com\\admin',
'dot path segment' => 'https://example.com/a/../admin',
'zero port' => 'https://example.com:0',
Expand Down
5 changes: 4 additions & 1 deletion tool-update-site-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,10 @@ function sqlite_wordpress_site_url_tool_validate_url( $value, $label ) {
if ( '' === $value || strlen( $value ) > 2048 ) {
throw new InvalidArgumentException( $label . ' must contain a URL no longer than 2048 bytes.' );
}
if ( preg_match( '/[\x00-\x20\x7F\\\\]/', $value ) ) {
if ( 1 !== preg_match( '//u', $value ) ) {
throw new InvalidArgumentException( $label . ' must contain valid UTF-8.' );
}
if ( preg_match( '/(?:[\x00-\x20\x7F\\\\]|\p{Z}|\x{0085})/u', $value ) ) {
throw new InvalidArgumentException( $label . ' must not contain whitespace, control characters, or backslashes.' );
}

Expand Down