Skip to content

Commit

Permalink
Fix issue with absolute URLs containing non ASCII characters
Browse files Browse the repository at this point in the history
  • Loading branch information
otsch committed Jan 31, 2024
1 parent 2eb26e4 commit f7cebb9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.1] - 2024-01-31
### Fixed
- An issue in the Validator, when trying to validate an absolute input URL that contains non ASCII characters.

## [2.1.0] - 2023-10-21
### Added
- Method `toPsr7()` to conveniently get a PSR-7 compatible instance from an `Url` instance. Basically wrapper for `new Uri($urlInstance)`.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 Christian Olear
Copyright (c) 2024 Christian Olear

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ private static function getValidUrlComponents(string $url, bool $onlyAbsoluteUrl
if (
is_array($components) &&
!empty($components) &&
($onlyAbsoluteUrl === false || filter_var($url, FILTER_VALIDATE_URL) !== false)
($onlyAbsoluteUrl === false || (array_key_exists('scheme', $components) && !empty($components['scheme'])))
) {
$components = self::filterEmptyStringComponents($components);
$validComponents = self::validateUrlComponents($components);
Expand Down
4 changes: 4 additions & 0 deletions tests/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
$relativeBaseUrl = new Url('/foo/bar?query=string#fragment');
$resolved = $resolver->resolve('https://www.example.com/examples', $relativeBaseUrl);
$this->assertEquals('https://www.example.com/examples', $resolved);

$baseUrl = new Url('https://www.example.com/foo');
$resolved = $resolver->resolve('https://www.example.com/foo/bar-bür-bör', $baseUrl);
$this->assertEquals('https://www.example.com/foo/bar-b%C3%BCr-b%C3%B6r', $resolved);
});

test('ResolvePaths', function () {
Expand Down
7 changes: 7 additions & 0 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
$this->assertNull(Validator::absoluteUrl('/foo/bar?query=string#fragment'));
});

test('validate an absolute URL containing non ASCII characters', function () {
$this->assertEquals(
'https://www.example.com/f%C3%B6%C3%B6',
Validator::absoluteUrl('https://www.example.com/föö')
);
});

test('ValidateAbsoluteUrlAndComponents', function () {
assertArrayContains(
Validator::absoluteUrlAndComponents('https://www.crwlr.software/packages/url/v0.1.2#installation'),
Expand Down

0 comments on commit f7cebb9

Please sign in to comment.