Skip to content

Commit

Permalink
Fixed sprintf format specifiers in URL breaking QueryBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Oct 16, 2018
1 parent 95e30b5 commit d6395e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Net/Http/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public static function mergeQuery($url, array $query)
$prefix = substr($url, 0, $pos);
$suffix = substr($url, $pos);

return sprintf("$prefix%s$queryString%s$suffix", $hasQuery ? '' : '?', $hasQuery ? '&' : '');
return sprintf(
'%s%s%s%s%s',
$prefix,
$hasQuery ? '' : '?',
$queryString,
$hasQuery ? '&' : '',
$suffix
);
}
}
7 changes: 7 additions & 0 deletions test/Unit/Porter/Net/Http/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public function provideQueries()
['quux' => 'quuz'],
'http://example.com?quux=quuz&foo=bar#baz?qux',
],

// Tests that format specifiers in URL do not break sprintf().
'Format specifier (sprintf)' => [
'http://example.com',
['foo' => '%s'],
'http://example.com?foo=%25s',
],
];
}
}

0 comments on commit d6395e4

Please sign in to comment.