Skip to content

GenericUrl converts plus sign into space within URI path component #398

Closed
@vasiliy-bout

Description

@vasiliy-bout

This is a simple junit test which fails but should work according to https://tools.ietf.org/html/rfc3986#section-3.3 because + sign is allowed to be used within a path component and has no special meaning when used within a path component:

    @Test
    public void testGenericUrl() throws URISyntaxException {
        final URI uri = new URI("http://foo.bar/path+with+plus");

        final GenericUrl genericUrl = new GenericUrl(uri);

        Assert.assertEquals("/path+with+plus", genericUrl.getRawPath());
        Assert.assertEquals(ImmutableList.of("", "path+with+plus"), genericUrl.getPathParts());
    }

This bug is related to #255 but shows different behaviour. We are using google-http-client library version 1.23.0:

        <dependency>
            <groupId>com.google.http-client</groupId>
            <artifactId>google-http-client</artifactId>
            <version>1.23.0</version>
        </dependency>

From the first glance on sources, it looks like there is a bug inside toPathParts methods implementation on line 550: https://github.com/google/google-http-java-client/blob/110b3ab6fa7838dbe9926038427c712db9ed8aae/google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java#L545-L553

There a call is made to CharEscapers.decodeUri which is invalid, because JavaDoc of this method explicitly states that it must not be used for path segments (see the second paragraph): https://github.com/google/google-http-java-client/blob/110b3ab6fa7838dbe9926038427c712db9ed8aae/google-http-client/src/main/java/com/google/api/client/util/escape/CharEscapers.java#L78-L90

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.priority: p2Moderately-important priority. Fix may not be included in next release.status: blockedResolving the issue is dependent on other work.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions