LibURL/Pattern: Ensure string passed through in process a URLPatternInit
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

Corresponds to: https://github.com/whatwg/urlpattern/commit/696b402
This commit is contained in:
Shannon Booth 2025-03-27 02:15:11 +13:00 committed by Tim Flynn
parent bee3720b6f
commit 212095e1c2
Notes: github-actions[bot] 2025-04-06 12:25:57 +00:00

View file

@ -302,12 +302,14 @@ PatternErrorOr<Init> process_a_url_pattern_init(Init const& init, PatternProcess
if (init.hostname.has_value())
result.hostname = TRY(process_hostname_for_init(init.hostname.value(), type));
// 16. If init["port"] exists, then set result["port"] to the result of process port for init given init["port"], result["protocol"], and type.
// FIXME: Spec bug, does not handle null protocol: https://github.com/whatwg/urlpattern/issues/257
if (init.port.has_value())
result.port = TRY(process_port_for_init(init.port.value(), result.protocol.value_or(String {}), type));
// 16. Let resultProtocolString be result["protocol"] if it exists; otherwise the empty string.
auto result_protocol_string = result.protocol.value_or(String {});
// 17. If init["pathname"] exists:
// 17. If init["port"] exists, then set result["port"] to the result of process port for init given init["port"], resultProtocolString, and type.
if (init.port.has_value())
result.port = TRY(process_port_for_init(init.port.value(), result_protocol_string, type));
// 18. If init["pathname"] exists:
if (init.pathname.has_value()) {
// 1. Set result["pathname"] to init["pathname"].
result.pathname = init.pathname.value();
@ -339,20 +341,19 @@ PatternErrorOr<Init> process_a_url_pattern_init(Init const& init, PatternProcess
}
}
// 3. Set result["pathname"] to the result of process pathname for init given result["pathname"], result["protocol"], and type.
// FIXME: Spec bug, does not handle a null protocol: https://github.com/whatwg/urlpattern/issues/257
result.pathname = TRY(process_pathname_for_init(result.pathname.value(), result.protocol.value_or(String {}), type));
// 3. Set result["pathname"] to the result of process pathname for init given result["pathname"], resultProtocolString, and type.
result.pathname = TRY(process_pathname_for_init(result.pathname.value(), result_protocol_string, type));
}
// 18. If init["search"] exists then set result["search"] to the result of process search for init given init["search"] and type.
// 19. If init["search"] exists then set result["search"] to the result of process search for init given init["search"] and type.
if (init.search.has_value())
result.search = process_search_for_init(init.search.value(), type);
// 19. If init["hash"] exists then set result["hash"] to the result of process hash for init given init["hash"] and type.
// 20. If init["hash"] exists then set result["hash"] to the result of process hash for init given init["hash"] and type.
if (init.hash.has_value())
result.hash = process_hash_for_init(init.hash.value(), type);
// 20. Return result.
// 21. Return result.
return result;
}