Skip to content

Commit 66c408f

Browse files
committed
Report failing position if parsing failed
1 parent 9889c73 commit 66c408f

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/main/generated/io/vertx/uritemplate/ExpandOptionsConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import io.vertx.core.json.JsonObject;
44
import io.vertx.core.json.JsonArray;
5-
import java.time.Instant;
6-
import java.time.format.DateTimeFormatter;
75

86
/**
97
* Converter and mapper for {@link io.vertx.uritemplate.ExpandOptions}.

src/main/java/io/vertx/uritemplate/impl/UriTemplateImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ public static class Parser {
318318

319319
public UriTemplateImpl parseURITemplate(String s) {
320320
template = new UriTemplateImpl();
321-
if (parseURITemplate(s, 0) != s.length()) {
322-
throw new IllegalArgumentException();
321+
int stop = parseURITemplate(s, 0);
322+
if (stop != s.length()) {
323+
throw new IllegalArgumentException("Error parsing template at position: " + stop);
323324
}
324325
for (Term term : template.terms) {
325326
if (term instanceof Expression && ((Expression) term).operator == Operator.FUTURE) {

src/test/java/io/vertx/tests/uritemplate/UriTemplateTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ public void testParseMaxLength() {
120120
assertEquals(4, new UriTemplateImpl.Parser().parseMaxLength("12345", 0));
121121
}
122122

123+
@Test
124+
public void testInvalidCharacter() {
125+
String template = "hello world";
126+
try {
127+
UriTemplate.of(template);
128+
fail("Was expecting " + template + " to fail");
129+
} catch (IllegalArgumentException ex) {
130+
assertEquals("Error parsing template at position: 5", ex.getMessage());
131+
}
132+
}
133+
123134
@Test
124135
public void testOpReserved() {
125136
assertInvalidTemplate("{!test}");

0 commit comments

Comments
 (0)