Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 9f32e27

Browse files
Merge pull request #48 from jayasheelankumar/master
Fixing the logic of Normalizing the URL
2 parents 64f9e38 + fbcdde7 commit 9f32e27

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

jsftemplating/src/main/java/com/sun/jsftemplating/util/fileStreamer/ResourceContentSource.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,30 @@ public static String normalize(String origPath) {
122122
// Normalize it...
123123
if ((path != null) && (path.length() > 0)) {
124124
path = path.replace('\\', '/');
125-
// Remove leading '/' chars
125+
// Remove leading '/' chars
126126
while ((path.length() > 0) && (path.charAt(0) == '/')) {
127127
path = path.substring(1);
128128
}
129-
// Replace all double "//" with "/"
129+
// Replace all double "//" with "/"
130130
while (path.indexOf("//") != -1) {
131131
path = path.replace("//", "/");
132-
}
133-
for (int idx = path.indexOf("../"); idx != -1; idx = path.indexOf("../")) {
132+
}
133+
for (int idx = path.indexOf("/../"); idx != -1; idx = path.indexOf("/../")) {
134134
if (idx == 0) {
135135
// Make sure we're not trying to go before the context root
136136
LogUtil.info("JSFT0010", origPath);
137137
throw new IllegalArgumentException(
138138
"Invalid Resource Path: '" + origPath + "'");
139139
}
140-
if (path.charAt(idx-1) != '/') {
141-
// Not a "../" match...
142-
continue;
143-
}
144140
// Create new path after evaluating ".."
145141
int prevPathIdx = path.lastIndexOf('/', idx-2) + 1;
146142
path = path.substring(0, prevPathIdx)// before x/../
147-
+ path.substring(idx + 3);// after x/../
143+
+ path.substring(idx + 4);// after x/../
148144
while ((path.length() > 0) && (path.charAt(0) == '/')) {
149145
// Remove leading '/' chars
150146
path = path.substring(1);
151147
}
152-
}
148+
}
153149
// We check for "../" so ".." at the end of a path could occur,
154150
// which is fine, unless it is also at the beginning...
155151
if (path.equals("..")) {
@@ -159,11 +155,10 @@ public static String normalize(String origPath) {
159155
// Last ensure path does not end in a '/'
160156
if (path.endsWith("/")) {
161157
path = path.substring(0, path.length()-1);
162-
}
158+
}
163159
}
164-
165160
return path;
166-
}
161+
}
167162

168163
/**
169164
* <p> This method may be used to clean up any temporary resources. It

0 commit comments

Comments
 (0)