refactor: replace url-parse to WHATWG URL API#2244
Conversation
Greptile SummaryThis PR replaces the third-party
Confidence Score: 3/5The migration to the WHATWG URL API is structurally sound, but the double-decode pattern left in all three call sites will crash edit/delete flows for any user whose key-file path or passphrase contains a The src/lib/remoteStorage.js, src/utils/Url.js, and src/pages/fileBrowser/fileBrowser.js all retain redundant Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Input URL string] --> B{URLParse shim}
B -->|valid URL| C[new URL - WHATWG]
B -->|throws TypeError| D[Fallback object\nempty strings + empty searchParams]
C --> E[URL object\nusername/password: percent-encoded\nsearchParams.get: already decoded]
D --> E
E --> F{Field type}
F -->|username / password| G[decodeURIComponent OK\nneeded - URL spec keeps these encoded]
F -->|searchParams.get values\nsecurity, mode, keyFile, passPhrase| H[decodeURIComponent WRONG\nalready decoded - double-decode\nthrows URIError if value contains bare %]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Input URL string] --> B{URLParse shim}
B -->|valid URL| C[new URL - WHATWG]
B -->|throws TypeError| D[Fallback object\nempty strings + empty searchParams]
C --> E[URL object\nusername/password: percent-encoded\nsearchParams.get: already decoded]
D --> E
E --> F{Field type}
F -->|username / password| G[decodeURIComponent OK\nneeded - URL spec keeps these encoded]
F -->|searchParams.get values\nsecurity, mode, keyFile, passPhrase| H[decodeURIComponent WRONG\nalready decoded - double-decode\nthrows URIError if value contains bare %]
|
|
WHATWG URL will throws on invalid input but url-parse not, maybe We should add exception handler? |
Yes |
|
@greptile review again |
|
@greptile review again |
|
@RohitKushvaha01 what about the double-decode problem? Because the query values on original |
In
url-parsereadme:So I think if We can do this for now :)