-
Notifications
You must be signed in to change notification settings - Fork 973
Don't break up as URL for autocomplete if location bar text isn't a URL #13693
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13693 +/- ##
==========================================
- Coverage 56.47% 56.45% -0.03%
==========================================
Files 283 283
Lines 28982 28983 +1
Branches 4807 4808 +1
==========================================
- Hits 16369 16361 -8
- Misses 12613 12622 +9
|
app/common/lib/siteSuggestions.js
Outdated
const parsedUrl = urlParse(url.toLowerCase()) | ||
const parsedUrl = isUrl(url) && urlParse(url.toLowerCase()) | ||
|
||
if (parsedUrl && (parsedUrl.hash || parsedUrl.host || parsedUrl.pathname || parsedUrl.query || parsedUrl.query || parsedUrl.protocol)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parsedUrl.query is repeated twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and force pushed
this looks useful, thanks! do you have a specific issue / STR that this fixes? |
06bd846
to
8d181ea
Compare
@diracdeltas no, sorry, do I need to open one? I saw a note about needing an issue but felt kind of silly opening both an issue and a PR saying the same thing. |
I did search through the issue list fwiw, lots of urlbar autocomplete reports but nothing that seemed to be specifically about this (which is surprising because this has an annoyance for me for a while) |
@rvagg yes please open an issue so that QA can check it. if this fixes some existing URL autocomplete issues, you can just link to those instead. |
Issue @ #13718 |
8d181ea
to
d308fd5
Compare
would you mind adding a unit test for this case in the tokenizeInput test in |
this works great, btw |
@diracdeltas well, there already are tests in there that cover this case. For instance: it('periods get tokenized', function () {
assert.deepEqual(tokenizeInput('brad.hates.primes'), ['brad', 'hates', 'primes'])
}) This passes now, and without this patch because it uses Node's
When you're running as a full browser, however, app/common/urlParse.js switches to Ideally we could have access to |
I will say, however, the fact that there is a lot depending on app/common/urlParse.js and changing to a fwiw this is a shim that I tried in app/common/urlParse.js that replaces - // TODO: move to the new node URL API: https://nodejs.org/api/url.html#url_url
- urlParse = require('url').parse
+ const url = require('url')
+ // modern Node.js with WHATWG URL parser
+ if (typeof url.URL === 'function') {
+ const urlProps = [ 'href', 'origin', 'protocol', 'username', 'password', 'host', 'hostname', 'port', 'pathname', 'search', 'searchParams', 'hash' ]
+ urlParse = (str) => {
+ try {
+ const parsedUrl = new url.URL(str)
+ // parsedUrl is not copyable via Object.assign(), so make a plain object
+ return urlProps.reduce((acc, curr) => {
+ acc[curr] = parsedUrl[curr]
+ return acc
+ }, {})
+ } catch (e) {
+ return null
+ }
+ }
+ } else {
+ // old version of Node.js
+ urlParse = url.parse
+ } (it's a bit ugly because the |
Oops, I forgot this bug only exists with muon.url.parse and so won't be encountered in unit tests by default
Actually I did create a way to run URL parser test using |
@rvagg i completely agree. It would be a priority for us to fix in the current codebase if we weren't migrating to a new codebase (https://github.com/brave/brave-browser) that doesn't have node integration at all, in which we'll only be using Chromium's URL parser. |
I've got three different variations of "before all" hook errors trying to get it to run unfortunately.
Another was a timeout "at windowHandles() - brave.js:278:32" and another was a selenium runtime error "unknown error: devTools is not defined". |
@rvagg forgot to mention, you have to do |
d308fd5
to
1ef653b
Compare
1ef653b
to
762a1b7
Compare
* muon unit test runner cleanup * muon unit test runner able to do async * muon unit test runner add before/affter Auditors: Test Plan:
762a1b7
to
26455ad
Compare
689c890 & 26455ad are not strictly part of this fix, you can take them or leave them. They extend your muon test runner to be able to handle tests that can be written for both mocha and within muon which reports back to mocha. The muon unit test runner now implements a simple test runner that does enough of what mocha does to allow tests to be mostly unmodified. Unfortunately they have to be split out into separate modules and exported as a nested object, where the keys are the test names and objects are the test functions. These are then either pulled into the muon test runner and use a wrapper around If you take out 370f8f6 and run the muon unit tests you'll see a couple of the siteSuggestion tests fail on tokenizing, which is the original bug. They don't fail with 370f8f6 in. Currently there are 3 tests failing in this current config, I haven't fixed them because they're not what I was trying to address and I think they may just be bad assumptions within the tests themselves so I figured I'd leave it to you to decide what to do with them. They point to the same problem we're addressing with this PR that the Node environment is artificial when there's places like urlParse.js that have a conditional switch between muon-native and node-native.
I know this may not fit what you're trying to do with the muon unit test runner, and I won't be upset if you decide not to take these commits, over to you. I enjoyed the spelunking anyway. I really just want the url suggest bug fixed, I'm running my own fork right now cause it annoys me so much to have it broken. As an aside:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- verified that manual test steps in URL-like strings can cause empty autocomplete results #13718 now pass
- verified unittests and
muon tests
webdriver test pass locally and on Travis (except for the exceptions noted) - opened some url tests work for node but not muon #13906 for the non-passing muon tests issue
@rvagg Thanks for the significant test improvements! I am really glad this points out some more issues with Node/Muon parsing compatibility. WRT asides,
cc @bbondy - can we address this in the new brave-browser repo?
It also fails for me locally, but passes on Travis somehow. I have opened #13907 |
master / 0.24.x: 2e63d0d |
Working on uplifting this to 0.23.x 😄 Code is not there yet... hang tight |
@bsclifton do you still need help uplifting? i can do it if so |
@diracdeltas yes- that would be awesome 😄 |
Don't break up as URL for autocomplete if location bar text isn't a URL
0.23.x: 7928737 |
fix #13718
Some urls that pass the
isUrl()
test don't parse properly into useful components by the muon URL parser which I believe is here.foo
andfoo.
are fine,foo.b
andfoo.bar
is not,foo.bar.
is fine again. What happens is thatisUrl()
says it can be parsed butmuon.url.parse()
returns an empty object so nothing gets tokenized.Instead of changing the muon behaviour, this change makes it more robust no matter which URL parser is used.
Unfortunately, the Node.js
url.parse()
function is much more liberal than what muon is using, it'll throw any old string intopath
andhref
if it can't work it out. So the unittest suite lies about it working.I attempted a conversion to the new Node.js WHATWG-compatible URL parser
url.URL
but that's even more different to what muon uses and breaks unittests for most other uses of urlParse.js so gave up on that idea. I've probably not ended up with the most elegant approach but it's minimal-touch to fix a bug.Test plan
github.c