1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[api-minor] Move the addDefaultProtocolToUrl/tryConvertUrlEncoding functionality into the createValidAbsoluteUrl function

Having recently worked with, and reviewed patches touching, this code it seemed that it's probably not a bad idea to move that functionality into `createValidAbsoluteUrl` as new options instead.

For the `addDefaultProtocolToUrl` functionality in particular, the existing helper function was not only moved but slightly improved as well. Looking at the code, I realized that there's a small risk that it would incorrectly match a *relative* URL-string too.

With these changes, the `createValidAbsoluteUrl` call-sites in the `src/core/`-code can be simplified a little bit.

*Please note:* This patch may, indirectly, change the format of the `unsafeUrl`-property returned with relevant Annotations and OutlineItems; hence the `api-minor` tag.
However, I'd argue that it's actually more correct this way since the whole purpose of `unsafeUrl` is/was to return the URL data as-is without any parsing done.
This commit is contained in:
Jonas Jenwald 2021-09-26 14:16:28 +02:00
parent 3b3c487bed
commit e6e04694f4
5 changed files with 42 additions and 48 deletions

View file

@ -796,7 +796,7 @@ describe("annotation", function () {
);
expect(data.annotationType).toEqual(AnnotationType.LINK);
expect(data.url).toEqual("http://www.hmrc.gov.uk/");
expect(data.unsafeUrl).toEqual("http://www.hmrc.gov.uk");
expect(data.unsafeUrl).toEqual("www.hmrc.gov.uk");
expect(data.dest).toBeUndefined();
}
);
@ -843,7 +843,7 @@ describe("annotation", function () {
).href
);
expect(data.unsafeUrl).toEqual(
stringToUTF8String("http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4")
"http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4"
);
expect(data.dest).toBeUndefined();
}