Skip to content

Commit

Permalink
fix: query parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tejmagar committed Jul 6, 2024
1 parent 8814848 commit 69d3c0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/src/main/java/org/tinyweb/commons/QueryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static HashMap<String, List<String>> queryParamsFromUrl(String rawUrl) {
String[] params = decodedUrl.split("&");
for (String param : params) {
String[] keyValue = param.split("=");
if (keyValue.length > 2) {

if (keyValue.length >= 2) {
String name = keyValue[0].trim();
String value = keyValue[1].trim();

Expand Down
12 changes: 10 additions & 2 deletions lib/src/main/java/org/tinyweb/paths/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@ public static PathParseResult parsePath(String rawPath) {

int firstQuestionMarkIndex = rawPath.indexOf("?");
if (firstQuestionMarkIndex == -1) {
pathParseResult.pathName = URLDecoder.decode(rawPath);
try {
pathParseResult.pathName = URLDecoder.decode(rawPath, "UTF-8");
} catch (UnsupportedEncodingException e) {
pathParseResult.pathName = rawPath;
}
pathParseResult.queryParams = new HashMap<>();
return pathParseResult;
}

// Skips question mark character
String pathName = rawPath.substring(0, firstQuestionMarkIndex);
pathParseResult.pathName = URLDecoder.decode(pathName);
try {
pathParseResult.pathName = URLDecoder.decode(pathName, "UTF-8");
} catch (UnsupportedEncodingException e) {
pathParseResult.pathName = pathName;
}

String rawQueryParams = rawPath.substring(firstQuestionMarkIndex + 1);
pathParseResult.queryParams = QueryUtil.queryParamsFromUrl(rawQueryParams);
Expand Down

0 comments on commit 69d3c0d

Please sign in to comment.