Skip to content
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

fix: When alias contains parameters, append ext error #1855

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/router/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function getFileName(path, ext) {
? path
: /\/$/g.test(path)
? `${path}README${ext}`
: `${path}${ext}`;
: path.indexOf('?') === -1
? `${path}${ext}`
: path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle all URLs the same with or without the query, just like regular HTML in a browser.

For example, /path/to/folder/?foo=123 has a query, and we still need to look for /path/to/folder/README.md?foo=123, but this skips anything with a query.

In the end, we need to operate on the path separately, and always send the query with the final result.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trusktr, is there anything that could help push this along? I'm not that familiar with js but I am good with regular expressions. If you can provide a little more context on the issue perhaps I could put a little time into it, as fixing this would open up a lot of doors for those of us needing to federate markdown files from private repos/orgs on GitHub.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vergilcw sorry for late reply. I think the solution should determine the fully qualified URL (f.e. anchor.href = partialUrlString; const fullyQualifiedUrl = anchor.href) and then use a new URL object to get all the pieces and use them correctly.

}

export class History {
Expand Down
31 changes: 31 additions & 0 deletions test/unit/router-history-base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,35 @@ describe('router/history/base', () => {
expect(url).toBe('/README');
});
});

// alias: uri
// ---------------------------------------------------------------------------
describe('getFile', () => {
// Tests
// -------------------------------------------------------------------------
test('path is url', () => {
const file = history.getFile('https://some/raw/url/README.md');

expect(file).toBe('https://some/raw/url/README.md');
});
test('path is url, but ext is .html', () => {
const file = history.getFile('https://foo.com/index.html');

expect(file).toBe('https://foo.com/index.html');
});
test('path is url, bug with parameters', () => {
sy-records marked this conversation as resolved.
Show resolved Hide resolved
const file = history.getFile(
'https://some/raw/url/README.md?token=Mytoken'
);

expect(file).toBe('https://some/raw/url/README.md?token=Mytoken');
});
test('path is url, but ext is different', () => {
history = new MockHistory({ ext: '.ext' });

const file = history.getFile('https://some/raw/url/README.md');

expect(file).toBe('https://some/raw/url/README.md.ext');
});
});
});