Skip to content

Commit

Permalink
allow guid pageids
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Vaughn committed Mar 5, 2020
1 parent 9a8cca8 commit fb14f8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ApiPlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public function at(...$segments) : object {
$segment = StringUtil::stringify($segment);
if(!in_array($segment, self::$rawUriPathSegments)) {

// auto-double encode, check for '=' sign
$segment = (strncmp($segment, '=', 1) === 0)
? '=' . self::urlEncode(substr($segment, 1), true)
// auto-double encode, check for '=' or ':' sign
$segment = StringUtil::startsWith($segment, '=') || StringUtil::startsWith($segment, ':')
? substr($segment, 0, 1) . self::urlEncode(substr($segment, 1), true)
: self::urlEncode($segment, true);
}
$path .= '/' . ltrim($segment, '/');
Expand Down
15 changes: 15 additions & 0 deletions tests/ApiPlug/at_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,19 @@ public function Can_add_non_urlencoded_segments() {
// assert
$this->assertEquals('http://foo.com/@api/deki/pages/=some%252Fpage/files,subpages/123/children,siblings?strict=true&dream.out.format=php', $plug->getUri());
}

/**
* @test
*/
public function Can_add_guid_segment() {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/@api/deki?strict=true'));

// act
$plug = $plug->at('pages', ':123', 'info');

// assert
$this->assertEquals('http://foo.com/@api/deki/pages/:123/info?strict=true&dream.out.format=php', $plug->getUri());
}
}

0 comments on commit fb14f8f

Please sign in to comment.