Skip to content

Commit

Permalink
Fix URIs beginning with /:p:/ being treated as absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Apr 29, 2021
1 parent 6438dcc commit af1a156
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ URI handling change log

## ?.?.? / ????-??-??

## 2.1.1 / 2021-04-29

* Fixed URIs beginning with `/:p:/` being treated as absolute - @thekid

## 2.1.0 / 2021-03-21

* Canonicalized path when resolving against relative URIs - @thekid
Expand Down
10 changes: 5 additions & 5 deletions src/main/php/util/URI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function __construct($base, $relative= null) {
$this->path= $base->path;
$this->query= $base->query;
$this->fragment= $base->fragment;
} else if (false !== ($p= strpos($base, ':'))) {
$this->scheme= substr($base, 0, $p);
if (!preg_match('!^([a-zA-Z][a-zA-Z0-9+.-]*)$!', $this->scheme)) {
throw new FormatException('Scheme "'.$this->scheme.'" malformed');
} else if (preg_match('/^([^:\/]*):(.+)/', $base, $matches)) {
if (!preg_match('!^([a-zA-Z][a-zA-Z0-9+.-]*)$!', $matches[1])) {
throw new FormatException('Scheme "'.$matches[1].'" malformed');
}
list($this->authority, $this->path, $this->query, $this->fragment)= $this->parse(substr($base, $p + 1));
$this->scheme= $matches[1];
list($this->authority, $this->path, $this->query, $this->fragment)= $this->parse($matches[2]);
} else {
$this->scheme= null;
list($this->authority, $this->path, $this->query, $this->fragment)= $this->parse($base);
Expand Down
3 changes: 3 additions & 0 deletions src/test/php/util/unittest/URITest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ private function relativeUris() {
yield [new URI('/index.html')];
yield [new URI('../../demo/index.html')];
yield [new URI('//example.com/?a=b')];
yield [new URI('/:p:/s/relative')];
yield [new URI('./:p:/s/self')];
yield [new URI('../:p:/s/parent')];
}

#[Test, Values('opaqueUris')]
Expand Down

0 comments on commit af1a156

Please sign in to comment.