Skip to content

Commit e1d0f87

Browse files
authored
Fix expression pattern compilation on android (#2136)
* Fix expression pattern compilation on android * Add test cases * Add license header * Reformat
1 parent b3aa337 commit e1d0f87

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

core/src/main/java/feign/template/Expressions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public final class Expressions {
3838
*
3939
* This is not a complete implementation of the rfc
4040
*
41-
* <a href="https://www.rfc-editor.org/rfc/rfc6570#section-2.2>RFC 6570 Expressions</a>
41+
* <a href="https://www.rfc-editor.org/rfc/rfc6570#section-2.2">RFC 6570 Expressions</a>
4242
*/
43-
private static final Pattern EXPRESSION_PATTERN =
44-
Pattern.compile("^(\\{([+#./;?&=,!@|]?)(.+)})$");
43+
static final Pattern EXPRESSION_PATTERN =
44+
Pattern.compile("^(\\{([+#./;?&=,!@|]?)(.+)\\})$");
4545

4646
// Partially From:
4747
// https://stackoverflow.com/questions/29494608/regex-for-uri-templates-rfc-6570-wanted -- I
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2012-2023 The Feign Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package feign.template;
15+
16+
import org.junit.jupiter.api.Test;
17+
import java.util.Collections;
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
public class ExpressionsTest {
21+
22+
@Test
23+
public void simpleExpression() {
24+
Expression expression = Expressions.create("{foo}");
25+
assertThat(expression).isNotNull();
26+
String expanded = expression.expand(Collections.singletonMap("foo", "bar"), false);
27+
assertThat(expanded).isEqualToIgnoringCase("foo=bar");
28+
}
29+
30+
@Test
31+
public void androidCompatibility() {
32+
// To match close brace on Android, it must be escaped due to the simpler ICU regex engine
33+
String pattern = Expressions.EXPRESSION_PATTERN.pattern();
34+
assertThat(pattern.contains("}")).isEqualTo(pattern.contains("\\}"));
35+
}
36+
}

0 commit comments

Comments
 (0)