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

URL: Use test data from web-platform-tests for isURL spec conformance #20537

Merged
merged 8 commits into from
Mar 11, 2020

Conversation

aduth
Copy link
Member

@aduth aduth commented Feb 28, 2020

Closes #20534

This pull request seeks to enhance tests for @wordpress/url isURL to conform to those defined by the Web Platform Tests project. As outlined in #20534, it includes a script to download and transform the URL test data, which is then loaded by the @wordpress/url unit tests as fixture data for the isURL tests.

You can run the script directly:

node packages/url/scripts/download-wpt-data.js

Testing Instructions:

Ensure unit tests pass:

npm run test-unit packages/url/src/test/index.test.js

@aduth aduth added [Type] Enhancement A suggestion for improvement. [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Package] Url /packages/url labels Feb 28, 2020
@aduth aduth requested a review from talldan as a code owner February 28, 2020 16:19
@github-actions
Copy link

github-actions bot commented Feb 28, 2020

Size Change: -1.34 kB (0%)

Total Size: 864 kB

Filename Size Change
build/annotations/index.js 3.43 kB +1 B
build/api-fetch/index.js 3.39 kB -1 B
build/block-editor/index.js 105 kB +219 B (0%)
build/block-editor/style-rtl.css 10.6 kB +156 B (1%)
build/block-editor/style.css 10.6 kB +154 B (1%)
build/block-library/editor-rtl.css 7.23 kB -428 B (5%)
build/block-library/editor.css 7.24 kB -428 B (5%)
build/block-library/index.js 115 kB -319 B (0%)
build/block-library/style-rtl.css 7.38 kB -111 B (1%)
build/block-library/style.css 7.39 kB -108 B (1%)
build/blocks/index.js 57.7 kB +42 B (0%)
build/components/index.js 191 kB -85 B (0%)
build/components/style-rtl.css 15.6 kB +50 B (0%)
build/components/style.css 15.6 kB +62 B (0%)
build/compose/index.js 5.75 kB -2 B (0%)
build/core-data/index.js 10.6 kB +151 B (1%)
build/data/index.js 8.22 kB +1 B
build/date/index.js 5.36 kB -4 B (0%)
build/dom-ready/index.js 569 B +1 B
build/edit-post/index.js 91.3 kB +374 B (0%)
build/edit-post/style-rtl.css 8.64 kB +112 B (1%)
build/edit-post/style.css 8.64 kB +113 B (1%)
build/edit-site/index.js 4.64 kB +9 B (0%)
build/edit-site/style-rtl.css 2.48 kB -29 B (1%)
build/edit-site/style.css 2.48 kB -28 B (1%)
build/edit-widgets/index.js 4.44 kB +18 B (0%)
build/edit-widgets/style-rtl.css 2.58 kB -8 B (0%)
build/edit-widgets/style.css 2.58 kB -7 B (0%)
build/editor/editor-styles-rtl.css 381 B +56 B (14%) ⚠️
build/editor/editor-styles.css 382 B +55 B (14%) ⚠️
build/editor/index.js 43.8 kB -816 B (1%)
build/editor/style-rtl.css 3.98 kB -29 B (0%)
build/editor/style.css 3.97 kB -29 B (0%)
build/element/index.js 4.45 kB +1 B
build/escape-html/index.js 734 B +1 B
build/format-library/index.js 7.09 kB -511 B (7%)
build/hooks/index.js 1.92 kB +1 B
build/i18n/index.js 3.49 kB +3 B (0%)
build/keyboard-shortcuts/index.js 2.3 kB +1 B
build/list-reusable-blocks/index.js 2.99 kB +1 B
build/nux/index.js 3.01 kB -16 B (0%)
build/plugins/index.js 2.54 kB -1 B
build/rich-text/index.js 14.3 kB +37 B (0%)
build/server-side-render/index.js 2.55 kB +6 B (0%)
build/url/index.js 4 kB -3 B (0%)
build/warning/index.js 1.14 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.01 kB 0 B
build/autop/index.js 2.58 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.02 kB 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-default-parser/index.js 1.65 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/data-controls/index.js 1.03 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom/index.js 3.06 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/html-entities/index.js 622 B 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keycodes/index.js 1.68 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 4.85 kB 0 B
build/notices/index.js 1.57 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/primitives/index.js 1.49 kB 0 B
build/priority-queue/index.js 780 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/viewport/index.js 1.61 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@aduth
Copy link
Member Author

aduth commented Feb 28, 2020

@SergioEstevao Note the failing native tests. Is this something you'd want or be able to take on? (i.e. fixing the implementation)

FAIL ../../packages/url/src/test/index.native.js
  isURL
    ✓ https://test:@test
    ✓ https://:@test
    ✕ non-special:https://test:@test/x (2ms)
    ✕ non-special:https://:@test/x (1ms)
    ✕ lolscheme:x x#x x
    ✓ file:https://example:1/ (1ms)
    ✓ file:https://example:test/
    ✕ file:https://example%/
    ✓ file:https://[example]/ (1ms)
    ✓ https://example.com/././foo
    ✓ https://example.com/./.foo
    ✓ https://example.com/foo/.
    ✓ https://example.com/foo/./ (1ms)
    ✓ https://example.com/foo/bar/..
    ✓ https://example.com/foo/bar/../
    ✓ https://example.com/foo/..bar
    ✓ https://example.com/foo/bar/../ton (4ms)
    ✓ https://example.com/foo/bar/../ton/../../a
    ✓ https://example.com/foo/../../..
    ✓ https://example.com/foo/../../../ton
    ✓ https://example.com/foo/%2e
    ✓ https://example.com/foo/%2e%2
    ✓ https://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar (1ms)
    ✓ https://example.com////../..
    ✓ https://example.com/foo/bar//../..
    ✓ https://example.com/foo/bar//..
    ✓ https://example.com/foo
    ✓ https://example.com/%20foo (1ms)
    ✓ https://example.com/foo% (1ms)
    ✓ https://example.com/foo%2
    ✓ https://example.com/foo%2zbar
    ✕ https://example.com/foo%2©zbar (1ms)
    ✓ https://example.com/foo%41%7a (1ms)
    ✕ https://example.com/foo	�%91
    ✓ https://example.com/foo%00%51 (1ms)
    ✕ https://example.com/(%28:%3A%29) (1ms)
    ✓ https://example.com/%3A%3a%3C%3c
    ✕ https://example.com/foo	bar (1ms)
    ✓ https://example.com\\foo\\bar
    ✓ https://example.com/%7Ffp3%3Eju%3Dduvgw%3Dd (1ms)
    ✓ https://example.com/@asdf%40
    ✕ https://example.com/你好你好
    ✕ https://example.com/‥/foo (1ms)
    ✕ https://example.com//foo
    ✕ https://example.com/‮/foo/‭/bar (1ms)
    ✓ https://www.google.com/foo?bar=baz#
    ✕ https://www.google.com/foo?bar=baz# »
    ✕ data:test# » (1ms)
    ✓ https://www.google.com
    ✓ https://192.0x00A80001
    ✓ https://www/foo%2Ehtml
    ✓ https://www/foo/%2E/html
    ✓ https://user:pass@/
    ✕ https://%25DOMAIN:[email protected]/
    ✕ http:\\www.google.com\foo
    ✓ https://foo:80/ (1ms)
    ✓ https://foo:81/
    ✓ httpa:https://foo:80/
    ✓ https://foo:-80/
    ✓ https://foo:443/
    ✓ https://foo:80/
    ✓ ftp:https://foo:21/ (1ms)
    ✓ ftp:https://foo:80/
    ✓ gopher:https://foo:70/
    ✓ gopher:https://foo:443/
    ✕ ws:https://foo:80/ (2ms)
    ✕ ws:https://foo:81/
    ✕ ws:https://foo:443/
    ✕ ws:https://foo:815/ (1ms)
    ✓ wss:https://foo:80/
    ✓ wss:https://foo:81/ (1ms)
    ✓ wss:https://foo:443/
    ✓ wss:https://foo:815/
    ✓ http:/example.com/
    ✓ ftp:/example.com/
    ✓ https:/example.com/
    ✕ madeupscheme:/example.com/ (1ms)
    ✓ file:/example.com/
    ✓ ftps:/example.com/
    ✓ gopher:/example.com/
    ✕ ws:/example.com/ (1ms)
    ✓ wss:/example.com/
    ✓ data:/example.com/
    ✕ javascript:/example.com/
    ✓ mailto:/example.com/ (1ms)
    ✓ http:example.com/
    ✓ ftp:example.com/
    ✓ https:example.com/
    ✕ madeupscheme:example.com/
    ✓ ftps:example.com/ (1ms)
    ✓ gopher:example.com/
    ✕ ws:example.com/
    ✓ wss:example.com/
    ✓ data:example.com/
    ✕ javascript:example.com/ (1ms)
    ✓ mailto:example.com/
    ✓ http:@www.example.com
    ✕ http:/@www.example.com (1ms)
    ✕ https://@www.example.com
    ✓ http:a:[email protected]
    ✓ http:/a:[email protected]
    ✓ https://a:[email protected] (1ms)
    ✕ https://@pple.com
    ✓ http::[email protected]
    ✓ http:/:[email protected]
    ✓ https://:[email protected]
    ✓ http:/:@/www.example.com (1ms)
    ✕ https://user@/www.example.com
    ✓ http:@/www.example.com
    ✓ http:/@/www.example.com
    ✓ https://@/www.example.com (1ms)
    ✓ https:@/www.example.com
    ✓ http:a:b@/www.example.com
    ✓ http:/a:b@/www.example.com
    ✓ https://a:b@/www.example.com
    ✓ http::@/www.example.com
    ✓ http:a:@www.example.com (1ms)
    ✓ http:/a:@www.example.com
    ✓ https://a:@www.example.com
    ✓ https://[email protected]
    ✓ http:@:www.example.com
    ✓ http:/@:www.example.com
    ✓ https://@:www.example.com
    ✓ https://:@www.example.com (1ms)
 
    ✓ https://�
    ✓ https://%EF%BF%BD
    ✕ https://x/�?�#� (1ms)
    ✕ https://faß.ExAmPlE/
    ✕ sc:https://faß.ExAmPlE/ (1ms)
    ✓ https://x x:12
    ✓ https://./
    ✓ https://../
    ✓ https://0..0x300/
    ✓ https://[www.google.com]/
    ✕ https://host/?'
    ✕ notspecial:https://host/?'
    ✓ about:/../
    ✓ data:/../ (1ms)
    ✕ javascript:/../
    ✓ mailto:/../
    ✕ sc:https://ñ.test/
    ✕ sc:https://�!"$&'()*+,-.;<=>^_`{|}~/ (1ms)
    ✓ sc:https:///
    ✓ sc:https:// /
    ✕ sc:https://%/
    ✓ sc:https://@/ (1ms)
    ✓ sc:https://te@s:t@/
    ✓ sc:https://:/
    ✓ sc:https://:12/
    ✓ sc:https://[/
    ✓ sc:https://\/
    ✓ sc:https://]/
    ✕ sc:\../ (7ms)
    ✓ sc::[email protected]
    ✕ wow:%NBD
    ✕ wow:%1G (1ms)
    ✕ wow:�
    ✕ ftp:https://example.com%80/ (1ms)
    ✕ ftp:https://example.com%A0/
    ✕ https://example.com%80/ (1ms)
    ✕ https://example.com%A0/
    ✕ ftp:https://%e2%98%83
    ✕ https://%e2%98%83 (1ms)
    ✓ https://127.0.0.1:10100/relative_import.html
    ✓ https://facebook.com/?foo=%7B%22abc%22
    ✓ https://localhost:3000/[email protected]
    ✕ h	t
p:https://h	o
t:9	0
0/p	a
h?q	u
ry#f	r
g (1ms)
    ✕ https://foo.bar/baz?qux#fobar
    ✕ https://foo.bar/baz?qux#foo"bar
    ✕ https://foo.bar/baz?qux#foo<bar (1ms)
    ✕ https://foo.bar/baz?qux#foo>bar
    ✕ https://foo.bar/baz?qux#foo`bar (1ms)
    ✓ https://0x.0x.0
    ✕ https://0x100000000/test
    ✕ https://256.0.0.1/test (1ms)
    ✓ file:https:///C%3A/
    ✓ file:https:///C%7C/
    ✕ file:\\// (1ms)
    ✕ file:\\\\
    ✕ file:\\\\?fox
    ✕ file:\\\\#guppy (1ms)
    ✓ file:https://spider///
    ✕ file:\\localhost//
    ✓ file:https:///localhost//cat (1ms)
    ✕ file:https://\/localhost//cat
    ✓ file:https://localhost//a//../..//
    ✕ file:https://example.net/C:/
    ✕ file:https://1.2.3.4/C:/
    ✕ file:https://[1::8]/C:/
    ✕ file:/C|/ (1ms)
    ✕ file:https://C|/
    ✕ file: (1ms)
    ✕ file:?q=v
    ✕ file:#frag (1ms)
    ✓ https://[0::0::0]
    ✓ https://[0:.0]
    ✓ https://[0:0:]
    ✓ https://[0:1:2:3:4:5:6:7.0.0.0.1] (1ms)
    ✓ https://[0:1.00.0.0.0]
    ✓ https://[0:1.290.0.0.0]
    ✓ https://[0:1.23.23]
    ✓ https://?
    ✓ https://#
    ✕ sc:https://ñ (1ms)
    ✕ sc:https://ñ?x
    ✕ sc:https://ñ#x (1ms)
    ✕ sc:https://?
    ✕ sc:https://#
    ✓ tftp:https://foobar.com/someconfig;mode=netascii (1ms)
    ✓ telnet:https://user:[email protected]:23/
    ✕ ut2004:https://10.10.10.10:7777/Index.ut2
    ✓ redis:https://foo:bar@somehost:6379/0?baz=bam&qux=baz
    ✓ rsync:https://foo@host:911/sup
    ✓ git:https://github.com/foo/bar.git (1ms)
    ✓ irc:https://myserver.com:6999/channel?passwd
    ✓ dns:https://fw.example.org:9999/foo.bar.org?type=TXT
    ✕ ldap:https://localhost:389/ou=People,o=JNDITutorial
    ✕ git+https://github.com/foo/bar (1ms)
    ✕ urn:ietf:rfc:2648
    ✕ tag:[email protected],2001:foo/bar (1ms)
    ✕ non-special:https://%E2%80%A0/
    ✕ non-special:https://H%4fSt/path (1ms)
    ✕ non-special:https://[1:2:0:0:5:0:0:0]/
    ✕ non-special:https://[1:2:0:0:0:0:0:3]/
    ✕ non-special:https://[1:2::3]:80/ (1ms)
    ✓ non-special:https://[:80/
    ✕ blob:https://example.com:443/
    ✓ blob:d3958f5c-0777-0845-9dcf-2cb28783acaf
    ✓ https://0177.0.0.0189 (1ms)
    ✓ https://0x7f.0.0.0x7g
    ✓ https://0X7F.0.0.0X7G
    ✓ https://[::127.0.0.0.1]
    ✕ https://[0:1:0:1:0:1:0:1]
    ✕ https://[1:0:1:0:1:0:1:0] (1ms)
    ✕ https://example.org/test?"
    ✓ https://example.org/test?#
    ✕ https://example.org/test?< (1ms)
    ✕ https://example.org/test?>
    ✕ https://example.org/test?⌣
    ✓ https://example.org/test?%23%23 (1ms)
    ✓ https://example.org/test?%GH
    ✕ https://example.org/test?a#%EF
    ✕ https://example.org/test?a#%GH (1ms)
    ✓ a
    ✓ a/ (1ms)
    ✓ a//
    ✕ https://example.org/test?a#bc

Early iterations included LICENSE fetching as string, but this was later changed to static file. As such, the utility is better served to include JSON parsing.
Interestingly, rejecting (throwing) does not itself halt execution.
@SergioEstevao
Copy link
Contributor

@aduth I had a look and tried to implement a solution based on a REGEX, but I got to the conclusion that I was almost impossible to implement one that validates correctly all the cases on the test set.

I was thinking couldn't we just import the full whatwg-url package in RN and use the URL class as we do in the web?

@etoledom did you try to do that on your previous implementation?

@aduth
Copy link
Member Author

aduth commented Mar 5, 2020

I was thinking couldn't we just import the full whatwg-url package in RN and use the URL class as we do in the web?

I had meant to circle back here before your comment. Coincidentally, I was going to suggest exactly the same.

There was some discussion in #20172 about this. Apparently there were some issues in Android, but it's unclear if those were caused specifically by react-native-url-polyfill, or the whatwg-url package it uses under the hood.

@aduth aduth mentioned this pull request Mar 9, 2020
@aduth
Copy link
Member Author

aduth commented Mar 10, 2020

Based on @charpeni's comment at #20172 (comment), I tried again to reincorporate react-native-url-polyfill. I've not tested this with the actual emulators (like in #20172 (comment)), but at least the tests seem to run okay. The results are slightly better than they were previously. The key failure now is with unicode support, which appears to be intentionally omitted from react-native-url-polyfill. I'm not entirely clear yet if this is something we'd be okay with. If it is, we'd need to expand upon the proposed exception logic to exclude these test cases.

See log: https://travis-ci.com/WordPress/gutenberg/jobs/296580166

@SergioEstevao
Copy link
Contributor

@aduth I will retry this on the simulators and see if all builds correctly now.

I also think it's a good idea to add the unicode test to the exception lists for now.

@aduth
Copy link
Member Author

aduth commented Mar 10, 2020

Some of the failures are a bit peculiar.

For example:

  ● isURL › ftp:https://example.com%80/
    expect(received).toBe(expected) // Object.is equality
    Expected: false
    Received: true
      35 | 		'%s',
      36 | 		( input, isFailure ) => {
    > 37 | 			expect( isURL( input ) ).toBe( ! isFailure );
         | 			                         ^
      38 | 		}
      39 | 	);
      40 | } );
      at toBe (packages/url/src/test/index.test.js:37:29)

I guess it's based on the forked differences of whatwg-url-without-unicode:

charpeni/whatwg-url@6bf57ad

I observe in the regular whatwg-url that it fails here, as a result of domainToASCII:

https://github.com/jsdom/whatwg-url/blob/aa7d237ec8dc6294314a0dfb47a4b26c7d523395/src/url-state-machine.js#L380-L381

image

I guess it may technically fall under the scope of "unicode" validation omitted by the fork?

Aside: Does bundle size matter as much in React Native to warrant worrying so much over the ~100kb difference between whatwg-url-without-unicode and whatwg-url ?

Anyways, I guess I can make add some exception logic for now, since these are edge cases, even if technically valid. But the closer we can align these, the better.

@charpeni
Copy link

Tests related to Unicode support were skipped in charpeni/whatwg-url@473d32f. Tests are still running on CircleCI, and react-native-url-polyfill does have a Detox setup to run the polyfill on an iOS simulator.

Aside: Does bundle size matter as much in React Native to warrant worrying so much over the ~100kb difference between whatwg-url-without-unicode and whatwg-url ?

A difference of ~341 KB*. 😬

Some context around this, It's worrying enough that it couldn't be included in the core of React Native, even with ~41 KB. Adding ~341 KB (+51%) to the bundle seems excessive to handle Unicode which are like 1% of URL use cases.

@aduth
Copy link
Member Author

aduth commented Mar 10, 2020

A difference of ~341 KB*. 😬

Ah, thanks for correcting. I think I had the number stuck in my mind from the 133kb of mappingTable.json, which is fair to say is not representative of the full difference.

Thanks for the extra context as well. I admit I have a tendency to obsess over the edge cases, but I think it's a case to consider being pragmatic, given the circumstances.

@SergioEstevao
Copy link
Contributor

@aduth I created a PR on GB-mobile project to add the polyfill library to the project again.

It looks it's building correctly now, and all tests are green. Just waiting for @etoledom to double-check the build issues.

Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GB mobile is working correctly with these changes now, so it's a :shipit: for me!

@aduth aduth merged commit f3ae6da into master Mar 11, 2020
@aduth aduth deleted the add/wpt-url-tests branch March 11, 2020 18:37
@github-actions github-actions bot added this to the Gutenberg 7.8 milestone Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Url /packages/url [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL: Use test data from web-platform-tests for isURL spec conformance
3 participants