Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with absolute URLs containing non ASCII characters #49

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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