-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix bug when data dir contains leading slash #1563
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
Conversation
When it contains leading slash, it creates url like "//data/..." which is interpretted as an absolute url.
| }); | ||
|
|
||
| it('ignores leading slash in dataDir', () => { | ||
| const router = createRouter('/data/', /*demoMode=*/false); |
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.
Shouldn't demoMode be true if these are tests for demoMode? Not sure it's necessary to test separately though given that this isn't really critical when in demo mode.
| ext: string, params?: URLSearchParams): string { | ||
|
|
||
| const url = new URL(`${window.location.origin}/${pathPrefix}${path}`); | ||
| const url = new URL(`${window.location.origin}`); |
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.
The URL wrapper is working pretty indirectly here, apparently by doing some implicit normalization when the properties are set (like adding a leading slash to the path). Can you add a comment to explain that?
| '/data/plugin/scalars/scalar'); | ||
| }); | ||
|
|
||
| it('ignores leading slash in dataDir', function() { |
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.
These tests logically are more testing createRouter() than pluginRoute(), and seem like either way they should be grouped with the existing test for "removes trailing slash from base route".
Can you also add an explicit test for the case where it adds a leading slash when there isn't one there? This is implicitly tested by the "removes trailing slash" test but it'd be better to have an explicit test. Or it could be merged with the test here as something like "ensures at least one leading slash in dataDir".
| '/data/plugin/scalars/scalar'); | ||
| }); | ||
|
|
||
| it('ignores leading slash in dataDir', function() { |
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.
Can we standardize the naming on "pathPrefix" as you used for createProdPath(), rather than "dataDir"? It's confusing that it's inconsistent between parts of the code and code vs tests, and "pathPrefix" both is clearer and matches the flag naming.
Nothing except these two files seems to reference dataDir, so I think just a find-replace would suffice.
nfelt
left a 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.
LGTM, thanks for the cleanup!
When it contains leading slash, it creates url like "//data/..." which
is interpretted as an absolute url.