Skip to content

Commit 811911e

Browse files
KonoMaxiMaximilian Konowski
and
Maximilian Konowski
authored
Fixed anchors (#34)
* correctly rejecting anchors * fetch correctly validates. Removing comment Co-authored-by: Maximilian Konowski <[email protected]>
1 parent 6e32e86 commit 811911e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

__tests__/fetch_request.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ describe('header handling', () => {
167167

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

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

197192
describe('query params are parsed', () => {
198193
test('anchors are rejected', () => {
199-
const testRequest = new FetchRequest("post", "localhost/test?a=1&b=2#anchor", { query: { c: 3 } })
200-
expect(testRequest.url).toBe("localhost/test?a=1&b=2&c=3")
201-
// const brokenRequest = new FetchRequest("post", "localhost/test#anchor", { query: { a: 1, b: 2, c: 3 } })
202-
// expect(brokenRequest.url).toBe("localhost/test?a=1&b=2&c=3")
194+
const mixedRequest = new FetchRequest("post", "localhost/test?a=1&b=2#anchor", { query: { c: 3 } })
195+
expect(mixedRequest.url).toBe("localhost/test?a=1&b=2&c=3")
196+
197+
const queryRequest = new FetchRequest("post", "localhost/test?a=1&b=2&c=3#anchor")
198+
expect(queryRequest.url).toBe("localhost/test?a=1&b=2&c=3")
199+
200+
const optionsRequest = new FetchRequest("post", "localhost/test#anchor", { query: { a: 1, b: 2, c: 3 } })
201+
expect(optionsRequest.url).toBe("localhost/test?a=1&b=2&c=3")
203202
})
204203
test('url and options are merged', () => {
205204
const urlAndOptionRequest = new FetchRequest("post", "localhost/test?a=1&b=2", { query: { c: 3 } })

src/fetch_request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class FetchRequest {
114114
}
115115

116116
get url () {
117-
return this.originalUrl.split('?')[0] + this.query
117+
return (this.originalUrl.split('?')[0]).split('#')[0] + this.query
118118
}
119119

120120
get responseKind () {

0 commit comments

Comments
 (0)