Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vospace-datamodel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VOSpace INAF
vospace-datamodel
Commits
3c2e7690
Commit
3c2e7690
authored
4 years ago
by
Sonia Zorba
Browse files
Options
Downloads
Patches
Plain Diff
Handled other special chars edge cases
parent
a9ec1449
No related branches found
No related tags found
No related merge requests found
Pipeline
#1011
passed
4 years ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java
+2
-2
2 additions, 2 deletions
src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java
src/test/java/it/inaf/oats/vospace/datamodel/NodeUtilsTest.java
+8
-3
8 additions, 3 deletions
...st/java/it/inaf/oats/vospace/datamodel/NodeUtilsTest.java
with
10 additions
and
5 deletions
src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java
+
2
−
2
View file @
3c2e7690
...
...
@@ -18,7 +18,7 @@ public class NodeUtils {
* characters are allowed. Front end needs to pay attention to other allowed
* characters like & and parenthesis in any case, also to avoid XSS attacks.
*/
private
static
final
Pattern
FORBIDDEN_CHARS
=
Pattern
.
compile
(
"[\\x00\\x08\\x0B\\x0C\\x0E-\\x1F"
+
Pattern
.
quote
(
"<>?\":\\|
'
*"
)
+
"]"
);
private
static
final
Pattern
FORBIDDEN_CHARS
=
Pattern
.
compile
(
"[\\x00\\x08\\x0B\\x0C\\x0E-\\x1F"
+
Pattern
.
quote
(
"<>?\":\\|
/'`
*"
)
+
"]"
);
/**
* Slash is a special character in defining REST endpoints and trying to
...
...
@@ -54,7 +54,7 @@ public class NodeUtils {
public
static
String
urlEncodePath
(
String
path
)
{
String
[]
parts
=
path
.
split
(
"/"
);
return
String
.
join
(
"/"
,
Arrays
.
stream
(
parts
)
.
map
(
p
->
URLEncoder
.
encode
(
p
,
StandardCharsets
.
UTF_8
))
.
map
(
p
->
URLEncoder
.
encode
(
p
,
StandardCharsets
.
UTF_8
)
.
replace
(
"+"
,
"%20"
)
)
.
collect
(
Collectors
.
toList
()));
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/it/inaf/oats/vospace/datamodel/NodeUtilsTest.java
+
8
−
3
View file @
3c2e7690
...
...
@@ -16,15 +16,15 @@ public class NodeUtilsTest {
@Test
public
void
testGetPathWithSpacesFromRequestURLString
()
{
String
requestUrl
=
"http://localhost/vospace/nodes/a/b/c%20d%20%C3%A4.pdf"
;
assertEquals
(
"/a/b/c d ä.pdf"
,
NodeUtils
.
getPathFromRequestURLString
(
requestUrl
));
String
requestUrl
=
"http://localhost/vospace/nodes/a/b/c%20d%20%C3%A4
+%2B
.pdf"
;
assertEquals
(
"/a/b/c d ä
+
.pdf"
,
NodeUtils
.
getPathFromRequestURLString
(
requestUrl
));
}
@Test
public
void
testEncodePathSpecialChars
()
{
String
specialChars
=
"ä è#+ /other/+-ò@"
;
assertEquals
(
"%C3%A4
+
%C3%A8%23%2B
+
/other/%2B-%C3%B2%40"
,
NodeUtils
.
urlEncodePath
(
specialChars
));
assertEquals
(
"%C3%A4
%20
%C3%A8%23%2B
%20
/other/%2B-%C3%B2%40"
,
NodeUtils
.
urlEncodePath
(
specialChars
));
}
@Test
...
...
@@ -41,6 +41,11 @@ public class NodeUtilsTest {
public
void
testIllegalQuotes
()
{
testIllegalChars
(
"\"'.pdf"
);
}
@Test
public
void
testIllegalSlashEncoded
()
{
testIllegalChars
(
"%2F.pdf"
);
}
private
void
testIllegalChars
(
String
illegalString
)
{
boolean
exception
=
false
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment