Skip to content

Commit

Permalink
Fix issue #32: Canonicalize URL before matching
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jan 21, 2018
1 parent f3ebeb1 commit d6d78c9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Web change log

## 0.11.0 / 2018-01-21

* Fixed issue #32: Canonicalize URL before matching - @thekid
* Changed handler return type from `void` to `var` and ensured anything
returned from a handler will be returned from routing and filters.
Implements functionality suggested in #31
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require" : {
"xp-framework/core": "^9.0 | ^8.0 | ^7.0",
"xp-framework/networking": "^9.0 | ^8.0 | ^7.0",
"xp-forge/uri": "^1.0",
"xp-forge/uri": "^1.2",
"php": ">=5.6.0"
},
"require-dev" : {
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/web/Request.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(Input $input) {
}

$this->method= $input->method();
$this->uri= new URI($input->scheme().'://'.$this->header('Host', 'localhost').$input->uri());
$this->uri= (new URI($input->scheme().'://'.$this->header('Host', 'localhost').$input->uri()))->canonicalize();
$this->input= $input;
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/php/web/unittest/RoutingTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,16 @@ public function with($verb, $expected) {
->route(new Request(new TestInput($verb, '/')))
);
}

#[@test, @values([
# '/api',
# '//api', '///api',
# '/test/../api', '/./api',
# '/../api', '/./../api',
#])]
public function request_canonicalized_before_matching($requested) {
$this->assertEquals($this->handlers['specific'], Routing::cast(['/api' => $this->handlers['specific']])
->route(new Request(new TestInput('GET', $requested)))
);
}
}

0 comments on commit d6d78c9

Please sign in to comment.