-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: correctly parse the path in getloc #4940
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughRewrote getLoc() path normalization in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
wled00/data/common.js (1)
86-102
: Critical: base-path derivation now includes filenames and root “/” empties, breaking non-settings pagesWhen URL has no “settings” segment (e.g., “/index.htm”),
paths
isn’t trimmed andlocip
becomeshost/index.htm
, sogetURL("/settings")
yields “…/index.htm/settings”. Root “/” also setsloc
due to[""]
length. Normalize segments, drop trailing files, then trim “settings”. Patch below.- let path = l.pathname; - let paths = path.slice(1,path.endsWith('/')?-1:undefined).split("/"); - - // remove settings paths to get the base url - const settingsIndex = paths.lastIndexOf("settings"); - const pathLength = paths.length; - if ( - settingsIndex != -1 && - (settingsIndex === pathLength - 1 || settingsIndex === pathLength - 2) - ) { - paths = paths.slice(0, settingsIndex); - } - - if (paths.length > 0) { + let path = l.pathname; + let paths = path.slice(1,path.endsWith('/')?-1:undefined).split("/"); + // normalize: drop empties from leading/trailing slashes + paths = paths.filter(Boolean); + // remove settings paths to get the base url + const settingsIndex = paths.lastIndexOf("settings"); + const endsWithSettings = settingsIndex !== -1 && (settingsIndex === paths.length - 1 || settingsIndex === paths.length - 2); + if (endsWithSettings) { + paths = paths.slice(0, settingsIndex); + } else if (paths.length && paths[paths.length - 1].includes(".")) { + // drop trailing file like index.htm + paths.pop(); + } + + if (paths.length > 0) { locproto = l.protocol; loc = true; locip = l.hostname + (l.port ? ":" + l.port : "") + "/" + paths.join('/'); }
🧹 Nitpick comments (1)
wled00/data/common.js (1)
92-93
: Use strict inequality for index checksPrefer
!== -1
over!= -1
forlastIndexOf
results. The patch above includes this.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
wled00/data/common.js
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
wled00/data/**/*.{htm,html,css,js}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use tabs for indentation in web UI files (.htm/.html/.css/.js) under wled00/data
Files:
wled00/data/common.js
🧬 Code graph analysis (1)
wled00/data/common.js (1)
wled00/data/index.js (1)
paths
(234-234)
🔇 Additional comments (1)
wled00/data/common.js (1)
88-96
: Use tabs for indentation in wled00/data/common.js (lines 88–96)
Script returned no output; verify these lines start with tabs (not spaces) to comply with wled00/data/* formatting rules.
I've come up with this: let paths = l.pathname.split("/").slice(1); // first is always empty
let settingsIndex = paths.lastIndexOf("settings");
paths = paths.slice(0,settingsIndex); // if we don't have "settings", remove last entry (empty / or file) Reasoning:
So, possible landing URL paths (that can call
|
Oooh, that's a really neat way to do it! I don't see why it wouldn't work. |
Co-authored-by: Blaž Kristan <blaz@kristan-sp.si>
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.
... and you are good.
Please do test as I currently do not have reverse proxy set up for WLED. |
works on my WLED instance where I was having issues :) |
If you put WLED behind a reverse proxy,
getLoc
will ignore the reverse proxy if it is only one subpath (for example, if I had WLED on/lights/
,getLoc
would not find the subpath, and settings pages would not load).Instead of blindly trimming the last path, this change has getLoc trim anything after
/settings/
.Summary by CodeRabbit
Bug Fixes
Refactor