Skip to content

Commit

Permalink
Fix RR match bug
Browse files Browse the repository at this point in the history
When matching literals we break out of the wrong loop

(cherry picked from commit 7dfe43a)
  • Loading branch information
stuartwdouglas authored and gsmet committed Oct 11, 2022
1 parent 59384f6 commit 0f812d5
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
Expand Up @@ -91,6 +91,9 @@ public RequestMatch<T> map(String path) {
break;
}
}
if (!matched) {
break;
}
} else if (segment.type == URITemplate.Type.DEFAULT_REGEX) {
if (matchPos == pathLength) {
matched = false;
Expand All @@ -103,6 +106,9 @@ public RequestMatch<T> map(String path) {
params[paramCount++] = URIDecoder.decodeURIComponent(path.substring(start, matchPos), false);
}
}
if (!matched) {
continue;
}
if (paramCount < params.length) {
params[paramCount] = null;
}
Expand All @@ -113,7 +119,7 @@ public RequestMatch<T> map(String path) {
doPrefixMatch = (matchPos == 1 || path.charAt(matchPos) == '/') //matchPos == 1 corresponds to '/' as a root level match
&& (prefixAllowed || matchPos == pathLength - 1); //if prefix is allowed, or the remainder is only a trailing /
}
if (matched && (fullMatch || doPrefixMatch)) {
if (fullMatch || doPrefixMatch) {
String remaining;
if (fullMatch) {
remaining = "";
Expand Down
@@ -0,0 +1,52 @@
package org.jboss.resteasy.reactive.server.vertx;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

public class CloseDelegateInputStream extends InputStream {

final InputStream delegate;
final Closeable closeable;

public CloseDelegateInputStream(InputStream delegate, Closeable closeable) {
this.delegate = delegate;
this.closeable = closeable;
}

@Override
public int read(byte[] b) throws IOException {
int ret = delegate.read(b);
if (ret == -1) {
delegate.close();
}
return ret;
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
int ret = delegate.read(b, off, len);
if (ret == -1) {
delegate.close();
}
return ret;
}

@Override
public void close() throws IOException {
try {
delegate.close();
} finally {
closeable.close();
}
}

@Override
public int read() throws IOException {
int ret = delegate.read();
if (ret == -1) {
delegate.close();
}
return ret;
}
}
Expand Up @@ -35,4 +35,15 @@ public void testRegexMatch() {
.statusCode(404);
}

@Test
public void testLiteralInRegex() {
RestAssured.get("/regex/abb/foo/alongpathtotriggerbug")
.then()
.statusCode(200)
.body(equalTo("plain:abb/foo/alongpathtotriggerbug"));
RestAssured.get("/regex/abb/literal/ddc")
.then()
.statusCode(200)
.body(equalTo("literal:abb/ddc"));
}
}
Expand Up @@ -13,4 +13,15 @@ public String hello(@PathParam("1p-_in.") String name) {
return "pin " + name;
}

@GET
@Path("{p1}/{p2:.*}/{p3:.*}")
public String noliteral(@PathParam("p1") String p1, @PathParam("p2") String p2, @PathParam("p3") String p3) {
return "plain:" + p1 + "/" + p2 + "/" + p3;
}

@GET
@Path("{p1}/literal/{p2:.*}")
public String literal(@PathParam("p1") String p1, @PathParam("p2") String p2) {
return "literal:" + p1 + "/" + p2;
}
}

0 comments on commit 0f812d5

Please sign in to comment.