Skip to content

Commit

Permalink
Trim URLs before parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox committed Mar 4, 2024
1 parent 08b7201 commit dae0688
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.3
=====

* (improvement) Trim URLs before parsing.


1.0.2
=====

Expand Down
2 changes: 2 additions & 0 deletions src/Video/VideoUrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function __construct (
*/
public function parseVideoUrl (string $url) : ?VideoDetails
{
$url = \trim($url);

foreach ($this->parsers as $parser)
{
$details = $parser->parseUrl($url);
Expand Down
1 change: 1 addition & 0 deletions tests/Video/VideoUrlParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function provideTestCases () : iterable
yield "youtu.be https" => ["https://youtu.be/1234567890_", VideoPlatform::YouTube, "1234567890_"];
yield "youtu.be http" => ["http://youtu.be/1234567890_", VideoPlatform::YouTube, "1234567890_"];
yield "youtube/oembed" => ["https://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D1234567890_&format=json", VideoPlatform::YouTube, "1234567890_"];
yield "youtube http with space" => ["https://www.youtube.com/watch?v=1234567890_ ", VideoPlatform::YouTube, "1234567890_"];

// YouTube: invalid
yield "youtube/watch invalid id" => ["http://www.youtube.com/watch?v=123456789012", null];
Expand Down

0 comments on commit dae0688

Please sign in to comment.