Closed Bug 1939658 Opened 2 months ago Closed 5 days ago

Replace new URL usage with URL.parse/URL.canParse where possible

Categories

(Firefox :: General, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
137 Branch
Tracking Status
firefox137 --- fixed

People

(Reporter: kernp25, Assigned: kernp25)

References

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0

Actual results:

Instead of using try { new URL(...) } catch (ex) {} just use URL.parse/URL.canParse.

Assignee: nobody → kernp25
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Duplicate of this bug: 1939657
Component: Untriaged → General
Severity: -- → N/A
Priority: -- → P1
See Also: → 1944832
Pushed by mbanner@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2c11770a86dc Replace new URL usage with URL.parse/URL.canParse where possible. r=robwu,Standard8,Gijs,mtigley,pdahiya,settings-reviewers,credential-management-reviewers,devtools-reviewers,tabbrowser-reviewers,places-reviewers,omc-reviewers,migration-reviewers,firefox-desktop-core-reviewers ,home-newtab-reviewers,webcompat-reviewers,urlbar-reviewers,twisniewski,mossop,dao,nchevobbe,webdriver-reviewers,whimboo,issammani,mconley,nbarrett,beth

Do you know why this test is failing? The test must be changed? It says parsedValue - null === "".

Flags: needinfo?(kernp25) → needinfo?(standard8)

(In reply to kernp25 from comment #5)

Do you know why this test is failing? The test must be changed? It says parsedValue - null === "".

At the start of the function, there's this line: let parsedParam = param;. In this case, I think it is setting parsedParam to the empty string. Your patch changes the code from try { parsedParam = new URI(param) } catch ... to parsedParam = URL.parse(param);.

Due to that change, if the param cannot be parsed, we're now returning null rather than "".

Looking at this documentation it might be acceptable to change the return type there - the result isn't valid, so we shouldn't be looking at the parsedParam anyway.

However, I don't know the code well enough here to know if that's acceptable, so forwarding the NI to :dmose who hopefully will have an eye..

Flags: needinfo?(standard8) → needinfo?(dmosedale)

Should I change the parsedParam = URL.parse(param); line to parsedParam = URL.parse(param) ?? "";?

Flags: needinfo?(standard8)

Or better, I should reset the parsedParam variable to parsedParam = param; here?

The options here are why I'm asking :dmose. I don't know enough to know if it is safe to change what we return (and hence we can update the test) or change the code to match the test. Whilst we could change the code rather than the test, that is then extra code that we'll need to explain.

Flags: needinfo?(standard8)

Can you now push again? The other case will be handled in bug 1946723.

Flags: needinfo?(dmosedale) → needinfo?(standard8)

(In reply to kernp25 from comment #10)

Can you now push again? The other case will be handled in bug 1946723.

Thank you, that's a good way of handling this, I've just trigged landing again.

Flags: needinfo?(standard8)
Pushed by mbanner@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8d3dea2426af Replace new URL usage with URL.parse/URL.canParse where possible. r=robwu,Standard8,Gijs,mtigley,pdahiya,settings-reviewers,credential-management-reviewers,devtools-reviewers,tabbrowser-reviewers,places-reviewers,omc-reviewers,migration-reviewers,firefox-desktop-core-reviewers ,home-newtab-reviewers,webcompat-reviewers,urlbar-reviewers,twisniewski,mossop,dao,nchevobbe,webdriver-reviewers,whimboo,issammani,mconley,nbarrett,beth
Status: ASSIGNED → RESOLVED
Closed: 5 days ago
Resolution: --- → FIXED
Target Milestone: --- → 137 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: