diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/helpers-test.ts | 21 | ||||
-rw-r--r-- | src/helpers.ts | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/helpers-test.ts b/src/helpers-test.ts new file mode 100644 index 000000000..4aac5ebec --- /dev/null +++ b/src/helpers-test.ts @@ -0,0 +1,21 @@ +import {test, TestLib} from "testlib/talertest"; +import * as helpers from "./helpers"; + + +test("URL canonicalization", (t: TestLib) => { + // converts to relative, adds https + t.assertEqualsStrict( + "https://alice.example.com/exchange/", + helpers.canonicalizeBaseUrl("alice.example.com/exchange")) + + // keeps http, adds trailing slash + t.assertEqualsStrict( + "http://alice.example.com/exchange/", + helpers.canonicalizeBaseUrl("http://alice.example.com/exchange")) + + // keeps http, adds trailing slash + t.assertEqualsStrict( + "http://alice.example.com/exchange/", + helpers.canonicalizeBaseUrl("http://alice.example.com/exchange#foobar")) + t.pass(); +}); diff --git a/src/helpers.ts b/src/helpers.ts index 26cd350ee..2e7a701c3 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -50,7 +50,7 @@ export function canonicalizeBaseUrl(url: string) { x.protocol("https"); } x.path(x.path() + "/").normalizePath(); - x.fragment(); + x.fragment(""); x.query(); return x.href() } |