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

Commit df9cdeb

Browse files
Michal GajdosGerrit Code Review
authored andcommitted
Merge "Updated default URI template value regex pattern."
2 parents 0efed4e + 5c76e58 commit df9cdeb

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

core-common/src/main/java/org/glassfish/jersey/uri/internal/UriTemplateParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -79,7 +79,10 @@ private static Set<Character> initReserved() {
7979
return s;
8080
}
8181

82-
private static final Pattern TEMPLATE_VALUE_PATTERN = Pattern.compile("[^/]+?");
82+
/**
83+
* Default URI template value regexp pattern.
84+
*/
85+
public static final Pattern TEMPLATE_VALUE_PATTERN = Pattern.compile("[^/]+");
8386

8487
private final String template;
8588
private final StringBuffer regex = new StringBuffer();

core-common/src/test/java/org/glassfish/jersey/uri/UriTemplateTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -49,6 +49,8 @@
4949
import java.util.Map;
5050
import java.util.regex.MatchResult;
5151

52+
import org.glassfish.jersey.uri.internal.UriTemplateParser;
53+
5254
import org.junit.Test;
5355
import static org.hamcrest.CoreMatchers.equalTo;
5456
import static org.junit.Assert.assertEquals;
@@ -217,7 +219,7 @@ public void testMatching() {
217219

218220
@Test
219221
public void testTemplateRegexes() {
220-
_testTemplateRegex("{a:}", "([^/]+?)");
222+
_testTemplateRegex("{a:}", "(" + UriTemplateParser.TEMPLATE_VALUE_PATTERN.pattern() + ")");
221223
_testTemplateRegex("{a:.*}", "(.*)");
222224
_testTemplateRegex("{a: .*}", "(.*)");
223225
_testTemplateRegex("{a: .* }", "(.*)");

core-server/src/test/java/org/glassfish/jersey/server/model/ResourceModelTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -37,7 +37,6 @@
3737
* only if the new code is made subject to such option by the copyright
3838
* holder.
3939
*/
40-
4140
package org.glassfish.jersey.server.model;
4241

4342
import java.util.List;
@@ -48,6 +47,8 @@
4847
import javax.ws.rs.PUT;
4948
import javax.ws.rs.Path;
5049

50+
import org.glassfish.jersey.uri.internal.UriTemplateParser;
51+
5152
import org.junit.Test;
5253
import static org.junit.Assert.assertEquals;
5354
import static org.junit.Assert.fail;
@@ -216,7 +217,7 @@ public static Resource getParentResource(RuntimeResource runtimeResource, String
216217
}
217218

218219
private void testTemplate(List<RuntimeResource> runtimeResources) {
219-
final String regexTemplate = "/([^/]+?)";
220+
final String regexTemplate = "/(" + UriTemplateParser.TEMPLATE_VALUE_PATTERN.pattern() + ")";
220221
final RuntimeResource template = ResourceTestUtils.getRuntimeResource(runtimeResources, regexTemplate);
221222
ResourceTestUtils.containsExactMethods(template, false, "GET", "PUT", "POST");
222223
final List<RuntimeResource> templateChildResources = template.getChildRuntimeResources();

docs/src/main/docbook/jaxrs-resources.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
55
6-
Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
6+
Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
77
88
The contents of this file are subject to the terms of either the GNU
99
General Public License Version 2 only ("GPL") or the Common Development
@@ -134,7 +134,7 @@ public class UserResource {
134134
If it is required that a user name must only consist of
135135
lower and upper case numeric characters then it is possible to declare a
136136
particular regular expression, which overrides the default regular
137-
expression, "[^/]+?", for example:
137+
expression, "[^/]+", for example:
138138
<programlisting language="java">@Path("users/{username: [a-zA-Z][a-zA-Z_0-9]*}")</programlisting>
139139
In this type of example the username variable will only match user names that begin with one upper or lower case letter and zero or more alpha numeric characters and the underscore character. If a user name does not match that a 404 (Not Found) response will occur.
140140
</para>

0 commit comments

Comments
 (0)