Skip to content

Fixed anchors #34

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

Merged
merged 2 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 8 additions & 9 deletions __tests__/fetch_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ describe('header handling', () => {

request = new FetchRequest("get", "localhost")
expect(request.fetchOptions.redirect).toBe("follow")

// maybe check for valid values and default to follow?
// https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
request = new FetchRequest("get", "localhost", { redirect: "nonsense"})
expect(request.fetchOptions.redirect).toBe("nonsense")
})

test('sets signal', () => {
Expand All @@ -196,10 +191,14 @@ describe('header handling', () => {

describe('query params are parsed', () => {
test('anchors are rejected', () => {
const testRequest = new FetchRequest("post", "localhost/test?a=1&b=2#anchor", { query: { c: 3 } })
expect(testRequest.url).toBe("localhost/test?a=1&b=2&c=3")
// const brokenRequest = new FetchRequest("post", "localhost/test#anchor", { query: { a: 1, b: 2, c: 3 } })
// expect(brokenRequest.url).toBe("localhost/test?a=1&b=2&c=3")
const mixedRequest = new FetchRequest("post", "localhost/test?a=1&b=2#anchor", { query: { c: 3 } })
expect(mixedRequest.url).toBe("localhost/test?a=1&b=2&c=3")

const queryRequest = new FetchRequest("post", "localhost/test?a=1&b=2&c=3#anchor")
expect(queryRequest.url).toBe("localhost/test?a=1&b=2&c=3")

const optionsRequest = new FetchRequest("post", "localhost/test#anchor", { query: { a: 1, b: 2, c: 3 } })
expect(optionsRequest.url).toBe("localhost/test?a=1&b=2&c=3")
})
test('url and options are merged', () => {
const urlAndOptionRequest = new FetchRequest("post", "localhost/test?a=1&b=2", { query: { c: 3 } })
Expand Down
2 changes: 1 addition & 1 deletion src/fetch_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class FetchRequest {
}

get url () {
return this.originalUrl.split('?')[0] + this.query
return (this.originalUrl.split('?')[0]).split('#')[0] + this.query
}

get responseKind () {
Expand Down