garycourt / uri-js

An RFC 3986 compliant, scheme extendable URI parsing/validating/normalizing/resolving library for JavaScript
Other
305 stars 68 forks source link

This library does not handle special signs in uri path segments #93

Closed steve-todorov closed 1 year ago

steve-todorov commented 1 year ago

Bug

The library is not able to handle special signs in the URI path segments.

Example test case

export function StringToEncodedURI(raw: string) {
  const parsed = URI.parse(raw);
  const serialized = URI.serialize(parsed);
  return serialized;
}

describe('Failing test', () => {

  it('should encode urls with special symbols', () => {
    const expected = "https://a.b/c%23/d/1697736474704%231.jpg"
    const result = StringToEncodedURI("https://a.b/c#/d/1697736474704#1.jpg")
    expect(result).toEqual(expected);
  })

});
garycourt commented 1 year ago

This library can handle escaping all non-URI symbols. The problem is that your test case is wrong. The "#" symbol is the separator character for the fragment, and URI.parse will treat it as such. You are responsible for escaping this character. It's like if you put an extra "/" somewhere in your URL and expect the library to know that this one character should be escaped and the others should not.

steve-todorov commented 1 year ago

I understand your reasoning. Our client has some paths in S3 that are using # within the path segments and was hoping this lib could be used to handle that case as well. Thanks for the reply @garycourt!