Skip to content

Ensure that the URI resolution semantic is consistent with Dart - #819

Merged
stof merged 1 commit into
scssphp:mainfrom
stof:test_uri_resolution
Nov 6, 2025
Merged

Ensure that the URI resolution semantic is consistent with Dart#819
stof merged 1 commit into
scssphp:mainfrom
stof:test_uri_resolution

Conversation

@stof

@stof stof commented Oct 29, 2025

Copy link
Copy Markdown
Member

Uri.resolveUri in Dart implements some behavior that is not part of the "Transform reference" algorithm of the RFC 3986 (which leaves some cases undefined behavior): https://github.com/dart-lang/sdk/blob/eaa7368470e2570bab8c9526803f8f20bdf29906/sdk/lib/core/uri.dart#L810-L823

We need to ensure that our UrlUtil implements the Dart semantic for this algorithm to keep our porting work simple (encapsulating that logic in a single place), including when upgrading league/uri (as discussed in #808, version 7.6 will become stricter).

The dart Uri.resolve API implements 3 behaviors that differ from the RFC3986 resolution algorithm:

  1. when resolving a relative path reference against a base URI with a scheme, no authority and a relative path, it treats it as if the base URI path was absolute (which seems to violate the behavior of the RFC)
  2. it supports resolving a relative path reference against a relative path base URL (instead of being an error case in the RFC3986) by merging the relative paths together to produce a new relative path (which preserves leading .. segments, unlike usual path resolution on absolute URLs)
  3. it supports resolving any kind of reference against a base URI without a scheme (for cases other than the previous case) by applying the algorithm of RFC3986 with an undefined scheme instead of a defined scheme (producing an undefined scheme in the result).

Case 1 and 2 are now implemented in our UriUtil to match the Dart behavior. The case 3 is covered already by the logic available in league/uri 7.5, which is why this inconsistency was not discovered until now.
Making that logic compatible with league/uri 7.6 (which performs strict validation of the RFC3986 algorithm) will be done separately.

@stof stof added this to the 2.1 milestone Oct 30, 2025
@stof
stof force-pushed the test_uri_resolution branch from 0b6994d to 9280fd3 Compare November 5, 2025 22:06
The dart `Uri.resolve` API implements 3 behaviors that differ from
the RFC3986 resolution algorithm:
1. when resolving a relative path reference against a base URI with a
  scheme, no authority and a relative path, it treats it as if the base
  URI path was absolute (which seems to violate the behavior of the RFC)
2. it supports resolving a relative path reference against a relative
  path base URL (instead of being an error case in the RFC3986) by
  merging the relative paths together to produce a new relative path
  (which preserves leading `..` segments, unlike usual path resolution
  on absolute URLs)
3. it supports resolving any kind of reference against a base URI without
  a scheme (for cases other than the previous case) by applying the
  algorithm of RFC3986 with an undefined scheme instead of a defined
  scheme (producing an undefined scheme in the result).

Case 1 and 2 are now implemented in our `UriUtil` to match the Dart
behavior. The case 3 is covered already by the logic available in
`league/uri` 7.5, which is why this inconsistency was not discovered
until now.
Making that logic compatible with `league/uri` 7.6 (which performs
strict validation of the RFC3986 algorithm) will be done separately.
@stof
stof force-pushed the test_uri_resolution branch from 9280fd3 to 0107fd9 Compare November 6, 2025 02:11
@stof
stof marked this pull request as ready for review November 6, 2025 02:11
@stof
stof merged commit 154dd2c into scssphp:main Nov 6, 2025
9 checks passed
@stof
stof deleted the test_uri_resolution branch November 6, 2025 02:22
@stof stof mentioned this pull request Nov 6, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant