Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Whitespace in url fixes #3167 #3168

Merged
merged 1 commit into from
Aug 15, 2016
Merged

Whitespace in url fixes #3167 #3168

merged 1 commit into from
Aug 15, 2016

Conversation

Sh1d0w
Copy link

@Sh1d0w Sh1d0w commented Aug 13, 2016

cc @bbondy @bridiver @bsclifton

This PR allows to open valid URLs whith whitespace in it such as

https://s10.postimg.org/snp1s3aah/Screenshot+from 2016-08-13 17-50-27.png

The original behaviour to query the search engine is preserved if you type a word or set of words. But if the string starts with scheme, no matter it has whitespace in it it will try to load the url.

What is the behaviour now?

String typed in the url bar Before Now
google.com open https://google.com open https://google.com
test searches for test searches for test
test test searches for test test searches for test test
http://example.com/test image.jpg searches for http://example.com/test image.jpg via default search engine opens http://example.com/test image.jpg

@@ -108,7 +108,7 @@ class UrlBar extends ImmutableComponent {
const isLocationUrl = isUrl(location)
// If control key is pressed and input has no space in it add www. as a prefix and .com as a suffix.
// For whitepsace we want a search no matter what.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably update this comment about whitespace and searching too.

@bridiver
Copy link
Collaborator

Thanks for the PR! Can you add some unit tests for this in urlUtilTest.js? I'm also not sure this is 100% correct because while spaces are legal in the path (encoded as %20), they are not legal in a domain name or the scheme. my protocol://blah, test domain.com, http: //domain.com, etc.. should return false for isUrl

@Sh1d0w
Copy link
Author

Sh1d0w commented Aug 14, 2016

@bridiver You are completely right. I have fixed this behaviour and added tests as you requested.

Do you want me to refactor appUrlUtil all across the codebase or it is in the scope of another ticket?

// for cases, data:uri and view-source:uri
const case4Reg = /^\w+:.*/
// for cases, data:uri, view-source:uri and about
const case4Reg = /^data|view-source|about\:.*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think those might just be examples and not an exhaustive list. We also have registered and app protocols like bitcoin, 1password, etc... @bbondy ?

@bridiver
Copy link
Collaborator

Thanks! Can you add just a few more tests to cover all the changes? The other cases I can think of are

  1. multiple words
  2. space in schema
  3. an arbitrary registered protocol
    if those pass I think this is good to merge

@bridiver
Copy link
Collaborator

can you do an npm run lint and fix any issues? The CI tests are failing on some lint issues

@Sh1d0w
Copy link
Author

Sh1d0w commented Aug 15, 2016

@bridiver I think linting is failing generally even on master, it is not a fault on my branch.

Can you please tell me what are the registered protocols for lastpass, bitcoint ect, so I can add them to the test as well? I believe they should invoke chrome-extension:// protocol, no?

@bridiver
Copy link
Collaborator

bridiver commented Aug 15, 2016

at least some of the lint errors appear to be related to these changes https://travis-ci.org/brave/browser-laptop/builds/152446285
don't worry about any lint errors that are not related to you changes, but feel free to fix them :)
I wouldn't worry too much about the exact protocols, but maybe add chrome-extension just to verify that - is valid for an extension. Maybe also check that chrome extension:// fails?

@bridiver
Copy link
Collaborator

lint normally runs as a precommit hook on other platforms, but doesn't run on windows. I'm switching it to a pre-push hook that should work everywhere

Add some more tests
@Sh1d0w
Copy link
Author

Sh1d0w commented Aug 15, 2016

@bridiver Fixed linting. Added few more test cases.

Let me know if you find anything else that seems not ok.

@bridiver
Copy link
Collaborator

Looks good! Just waiting for CI to finish and I'll merge if everything looks good there. I know some tests are broken in master right now so I'm only looking for yours to pass.

@Sh1d0w
Copy link
Author

Sh1d0w commented Aug 15, 2016

@bridiver Cool, thanks man!

@bridiver bridiver merged commit c0dc16b into brave:master Aug 15, 2016
@bridiver
Copy link
Collaborator

++

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

Successfully merging this pull request may close these issues.

6 participants