]> Cypherpunks.ru repositories - gostls13.git/commit
net/http: unescape paths and patterns by segment
authorJonathan Amsterdam <jba@google.com>
Fri, 22 Sep 2023 19:57:46 +0000 (15:57 -0400)
committerJonathan Amsterdam <jba@google.com>
Mon, 25 Sep 2023 16:46:51 +0000 (16:46 +0000)
commit3563792768b1e06da4a0cb5f946adf90d1297766
treedee274d533e2e1b622640ea863918e2dbe3871d9
parentb7e0dfc437edf6d744dfdf9f4613bee26ea08e31
net/http: unescape paths and patterns by segment

When parsing patterns and matching, split the path into segments at
slashes, then unescape each segment.

This behaves as most people would expect:

- The pattern "/%61" matches the paths "/a" and "/%61".

- The pattern "/%7B" matches the path "/{". (If we did not unescape
  patterns, there would be no way to write that pattern: because "/{"
  is a parse error because it is an invalid wildcard.)

- The pattern "/user/{u}" matches "/user/john%2Fdoe" with u set to
  "john/doe".

- The unexpected redirections of #21955 will not occur.

A later CL will restore the old behavior behind a GODEBUG setting.

Updates #61410.

Fixes #21955.

Change-Id: I99025e149021fc94bf87d351699270460db532d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/530575
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/http/pattern.go
src/net/http/pattern_test.go
src/net/http/request_test.go
src/net/http/routing_tree.go
src/net/http/routing_tree_test.go
src/net/http/server.go