Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
af9f606d
Commit
af9f606d
authored
Feb 22, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Feb 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix annotation error due to URI encoding
parent
ae9894dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
html-metadata.ts
src/annotator/integrations/html-metadata.ts
+11
-4
html-metadata-test.js
src/annotator/integrations/test/html-metadata-test.js
+19
-0
No files found.
src/annotator/integrations/html-metadata.ts
View file @
af9f606d
...
...
@@ -47,16 +47,23 @@ export class HTMLMetadata {
* Returns the primary URI for the document being annotated
*/
uri
():
string
{
let
uri
=
decodeURIComponent
(
this
.
_getDocumentHref
());
let
uri
=
this
.
_getDocumentHref
();
// Get the URI without decoding it first
// Use the `link[rel=canonical]` element's href as the URL if present.
// Attempt to decode the URI, handle exceptions if the URI is malformed
try
{
uri
=
decodeURIComponent
(
uri
);
}
catch
(
error
)
{
// Log error for debugging. After this point we fall back to the original URI
console
.
error
(
'Error decoding URI:'
,
error
);
}
// Use the `link[rel=canonical]` element's href as the URI if present.
const
links
=
this
.
_getLinks
();
for
(
const
link
of
links
)
{
if
(
link
.
rel
===
'canonical'
)
{
uri
=
link
.
href
;
uri
=
link
.
href
;
// Assuming canonical hrefs are correctly encoded
}
}
return
uri
;
}
...
...
src/annotator/integrations/test/html-metadata-test.js
View file @
af9f606d
...
...
@@ -405,5 +405,24 @@ describe('HTMLMetadata', () => {
assert
.
equal
(
doc
.
uri
(),
canonicalLink
.
href
);
});
it
(
'should log an error if URI is not decodable'
,
()
=>
{
// '%%CUST_ID%%' is an invalid escape sequence, so it will throw a URIError when decoded
const
badURI
=
'https://example.com/?foo=%%CUST_ID%%'
;
const
doc
=
createDoc
(
badURI
);
const
consoleErrorSpy
=
sinon
.
stub
(
console
,
'error'
);
try
{
assert
.
equal
(
badURI
,
doc
.
uri
());
assert
.
calledOnce
(
consoleErrorSpy
);
assert
.
calledWith
(
consoleErrorSpy
,
'Error decoding URI:'
,
sinon
.
match
.
instanceOf
(
URIError
),
);
}
finally
{
console
.
error
.
restore
();
}
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment