Repository navigation
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.
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”),
pathsisn’t trimmed andlocipbecomeshost/index.htm, sogetURL("/settings")yields “…/index.htm/settings”. Root “/” also setslocdue 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
!== -1over!= -1forlastIndexOfresults. 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 <[email protected]>
|
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 :) |
|
Hey! This pull request has been open for quite some time without any new comments now. It will be closed automatically in a week if no further activity occurs. |
|
Re "awaiting testing": Works on my end. |
|
Can this be merged? |
|
bump? |
|
@netmindz this might be more in your direction of expertise. |
|
Hey! This pull request has been open for quite some time without any new comments now. It will be closed automatically in a week if no further activity occurs. |
|
@netmindz I have no idea what a reverse proxy even is. can you check if this makes sense? |
If you put WLED behind a reverse proxy,
getLocwill ignore the reverse proxy if it is only one subpath (for example, if I had WLED on/lights/,getLocwould 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