Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ef367d43
Commit
ef367d43
authored
Feb 15, 2021
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add base-case tests and more JSDoc description / examples (review)
parent
5e63282d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
app/assets/javascripts/lib/utils/url_utility.js
app/assets/javascripts/lib/utils/url_utility.js
+14
-0
spec/frontend/lib/utils/url_utility_spec.js
spec/frontend/lib/utils/url_utility_spec.js
+10
-0
No files found.
app/assets/javascripts/lib/utils/url_utility.js
View file @
ef367d43
...
...
@@ -23,6 +23,20 @@ function decodeUrlParameter(val) {
* If you need to use search parameters or URL fragments, they should be
* added AFTER calling this function, not before.
*
* Usecase: An image filename is stored verbatim, and you need to load it in
* the browser.
*
* Example: /some_path/file #1.jpg ==> /some_path/file%20%231.jpg
* Example: /some-path/file! Final!.jpg ==> /some-path/file%21%20Final%21.jpg
*
* Essentially, if a character *could* present a problem in a URL, it's escaped
* to the hexadecimal representation instead. This means it's a bit more
* aggressive than encodeURIComponent: that built-in function doesn't
* encode some characters that *could* be problematic, so this function
* adds them (#, !, ~, *, ', (, and )).
* Additionally, encodeURIComponent *does* encode `/`, but we want safer
* URLs, not non-functional URLs, so this function DEcodes slashes ('%2F').
*
* @param {String} potentiallyUnsafePath
* @returns {String}
*/
...
...
spec/frontend/lib/utils/url_utility_spec.js
View file @
ef367d43
...
...
@@ -902,5 +902,15 @@ describe('URL utility', () => {
expect
(
urlUtils
.
encodeSaferUrl
(
input
)).
toBe
(
output
);
},
);
it
.
each
`
character | input
${
'
/, .
'
}
|
${
'
/url/hello.png
'
}
${
'
\\
d
'
}
|
${
'
/url/hello123.png
'
}
${
'
-
'
}
|
${
'
/url/hello-123.png
'
}
${
'
_
'
}
|
${
'
/url/hello_123.png
'
}
`
(
'
makes no changes to unproblematic characters ($character)
'
,
({
input
})
=>
{
expect
(
urlUtils
.
encodeSaferUrl
(
input
)).
toBe
(
input
);
});
});
});
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