Skip to content

Commit

Permalink
Fixed issue perwendel#1026 implementation and unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
A.Lepe committed Aug 11, 2022
1 parent ffab528 commit de9a849
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 33 deletions.
10 changes: 5 additions & 5 deletions PR-STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ This is the current status for each PR:
* perwendel/spark#1183 opened on Jul 21, 2020 by luneo7

### Merged (Release 4)
* :green_circle: **MERGERD**: Fix perwendel/spark/issues/1077 : Solve the bad route selection based on acceptType
* :green_circle: **MERGED**: Fix perwendel/spark/issues/1077 : Solve the bad route selection based on acceptType
* perwendel/spark#1238 opened on May 21, 2021 by Chauncey-Xxy
* :green_circle: **MERGED AND FIXED**: fix issue perwendel/spark/issues/1204
* perwendel/spark#1236 opened on May 21, 2021 by FhToday
* :green_circle: **CHERRY PICKED**: Solve the problem of non-ASCII characters in URL. Try to fix #1026
* perwendel/spark#1222 opened on Apr 23, 2021 by Bugjudger


### Rejected
Expand All @@ -88,10 +92,6 @@ This is the current status for each PR:

### To Fix / To Discuss

* :yellow_circle: **TEST FAILING**: fix issue perwendel/spark/issues/1204
* perwendel/spark#1236 opened on May 21, 2021 by FhToday
* :yellow_circle: **TEST FAILING**: Solve the problem of non-ASCII characters in URL. Try to fix #1026
* perwendel/spark#1222 opened on Apr 23, 2021 by Bugjudger
* :yellow_circle: **MAY BREAK CODE (package name will change)**: Provide Automatic-Module-Name attribute in MANIFEST.MF (issue perwendel/spark/issues/961)
* perwendel/spark#1212 opened on Mar 10, 2021 by apssouza22
* :yellow_circle: **MERGE FAILS (#1030 was closed as not-wanted)**: Try to Fix issue perwendel/spark/issues/1022 & perwendel/spark/issues/1030 bug-fix
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ Improvements:
* Regex support in paths
* HTTP/2 support (perwendel#1183)

More details on these features: [DIFFERENCES.md](DIFFERENCES.md)
## Release4
* Fixed optional trailing slash when used with params
* Added unicode support in paths (issue perwendel#1026) (PR: perwendel/spark#1222)
* Fixed incorrect response based on acceptType (perwendel#1077) (PR: perwendel/spark#1238)
* Fixed incorrect handling when using invalid methods (perwendel/spark#1236) (PR: perwendel#1204)

More details and examples on the differences between the Official version and this one: [DIFFERENCES.md](DIFFERENCES.md)

----------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/spark/http/matching/MatcherFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.util.List;
import java.net.URLDecoder;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
Expand Down Expand Up @@ -106,6 +107,7 @@ public void doFilter(ServletRequest servletRequest,

String httpMethodStr = method.toLowerCase();
String uri = httpRequest.getRequestURI();
uri = URLDecoder.decode(uri, "UTF-8");
String acceptType = httpRequest.getHeader(ACCEPT_TYPE_REQUEST_MIME_HEADER);

List<RouteMatch> routes = routeMatcher.findAll();
Expand Down
38 changes: 13 additions & 25 deletions src/test/java/spark/GenericIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -328,24 +327,14 @@ public void testEchoParam3() throws Exception {
Assert.assertEquals("echo: " + polyglot, response.body);
}

// NOTE: To support multiple languages in paths, we are using URLDecode, which in this case,
// it will convert '+' into ' '
@Test
public void testPathParamsWithPlusSign() throws Exception {
String pathParamWithPlusSign = "not+broken+path+param";
UrlResponse response = doMethod("GET", "/param/" + pathParamWithPlusSign, null);
Assert.assertEquals(200, response.status);
Assert.assertEquals("echo: " + pathParamWithPlusSign, response.body);
}

// FIXME: http2 is failing due to: https://github.com/eclipse/jetty.project/issues/6132
// also: https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/http/UriCompliance.html
// to fix it: update to Jetty 10+ ?
@Ignore @Test
public void testParamWithEncodedSlash() throws Exception {
String polyglot = "te/st";
String encoded = URLEncoder.encode(polyglot, "UTF-8");
UrlResponse response = doMethod("GET", "/param/" + encoded, null);
Assert.assertEquals(200, response.status);
Assert.assertEquals("echo: " + polyglot, response.body);
Assert.assertEquals("echo: " + pathParamWithPlusSign.replace("+"," "), response.body);
}

@Test
Expand All @@ -354,32 +343,31 @@ public void testParamWithEncodedSpace() throws Exception {
String encoded = URLEncoder.encode(polyglot, "UTF-8");
UrlResponse response = doMethod("GET", "/param/" + encoded, null);
Assert.assertEquals(200, response.status);
Assert.assertEquals("echo: " + polyglot.replace(" ", "+"), response.body);
Assert.assertEquals("echo: " + polyglot, response.body);
}

// FIXME: http2 FIXME comment above
@Ignore @Test
public void testSplatWithEncodedSlash() throws Exception {
String param = "fo/shizzle";
@Test
public void testSplatWithEncodedSpace() throws Exception {
String param = "fo shizzle";
String encodedParam = URLEncoder.encode(param, "UTF-8");
String splat = "mah/FRIEND";
String splat = "mah FRIEND";
String encodedSplat = URLEncoder.encode(splat, "UTF-8");
UrlResponse response = doMethod("GET",
"/paramandwild/" + encodedParam + "/stuff/" + encodedSplat, null);
Assert.assertEquals(200, response.status);
Assert.assertEquals("paramandwild: " + param.replace(" ", "+") + splat, response.body);
Assert.assertEquals("paramandwild: " + param + splat, response.body);
}

@Test
public void testSplatWithEncodedSpace() throws Exception {
String param = "fo shizzle";
public void testSplatWithUTF8() throws Exception {
String param = "私のもの";
String encodedParam = URLEncoder.encode(param, "UTF-8");
String splat = "mah FRIEND";
String splat = "何でも大丈夫です。";
String encodedSplat = URLEncoder.encode(splat, "UTF-8");
UrlResponse response = doMethod("GET",
"/paramandwild/" + encodedParam + "/stuff/" + encodedSplat, null);
Assert.assertEquals(200, response.status);
Assert.assertEquals("paramandwild: " + param.replace(" ", "+") + splat, response.body);
Assert.assertEquals("paramandwild: " + param + splat, response.body);
}

@Test
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/spark/Issue1026Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package spark;
import org.junit.Before;
import org.junit.Test;

import spark.util.SparkTestUtil;

import static org.junit.Assert.*;
import static spark.Spark.*;
/**
* @since 2022/08/11.
*/
public class Issue1026Test {
private static final String ROUTE = "/api/v1/管理者/";
private static SparkTestUtil http;

@Before
public void setup() {
http = new SparkTestUtil(4567);
get(ROUTE, (q,a)-> "Get filter matched");
awaitInitialization();
}

@Test
public void testUrl() throws Exception {
SparkTestUtil.UrlResponse response = http.get(ROUTE);
assertEquals(200,response.status);
}
}
2 changes: 0 additions & 2 deletions src/test/java/spark/examples/hello/HelloWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package spark.examples.hello;

import static spark.Spark.get;
import static spark.Spark.staticFileLocation;

/**
* Minimal example
Expand All @@ -28,7 +27,6 @@
public class HelloWorld {

public static void main(String[] args) {
staticFileLocation("/public/");
get("/", (request, response) -> "Hello World!");

}
Expand Down

0 comments on commit de9a849

Please sign in to comment.