Skip to content

Commit 3619364

Browse files
committed
core/internal: fix regex pattern
1 parent 7052d8b commit 3619364

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

core/src/main/java/io/grpc/internal/ManagedChannelImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public final class ManagedChannelImpl extends ManagedChannel implements WithLogI
8484
// Matching this pattern means the target string is a URI target or at least intended to be one.
8585
// A URI target must be an absolute hierarchical URI.
8686
// From RFC 2396: scheme = alpha *( alpha | digit | "+" | "-" | "." )
87-
private static final Pattern URI_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9+-.]*:/.*");
87+
@VisibleForTesting
88+
static final Pattern URI_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9+.-]*:/.*");
8889

8990
private static final ClientTransport SHUTDOWN_TRANSPORT =
9091
new FailingClientTransport(Status.UNAVAILABLE.withDescription("Channel is shutdown"));

core/src/main/java/io/grpc/internal/ManagedClientTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface ManagedClientTransport extends ClientTransport, WithLogId {
7070

7171
/**
7272
* Receives notifications for the transport life-cycle events. Implementation does not need to be
73-
* thread-safe, so notifications must be properly sychronized externally.
73+
* thread-safe, so notifications must be properly synchronized externally.
7474
*/
7575
interface Listener {
7676
/**

core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,16 @@ public void firstResolvedServerConnectedThenDisconnected() throws Exception {
613613
verify(transport2, timeout(1000)).newStream(same(method), same(headers));
614614
}
615615

616+
@Test
617+
public void uriPattern() {
618+
assertTrue(ManagedChannelImpl.URI_PATTERN.matcher("a:/").matches());
619+
assertTrue(ManagedChannelImpl.URI_PATTERN.matcher("Z019+-.:/!@ #~ ").matches());
620+
assertFalse(ManagedChannelImpl.URI_PATTERN.matcher("a/:").matches()); // "/:" not matched
621+
assertFalse(ManagedChannelImpl.URI_PATTERN.matcher("0a:/").matches()); // '0' not matched
622+
assertFalse(ManagedChannelImpl.URI_PATTERN.matcher("a,:/").matches()); // ',' not matched
623+
assertFalse(ManagedChannelImpl.URI_PATTERN.matcher(" a:/").matches()); // space not matched
624+
}
625+
616626
private static class FakeBackoffPolicyProvider implements BackoffPolicy.Provider {
617627
@Override
618628
public BackoffPolicy get() {

0 commit comments

Comments
 (0)