MCPcopy Create free account
hub / github.com/ada-url/ada / parse_init

Function parse_init

tests/wpt_urlpattern_tests.cpp:397–438  ·  view source on GitHub ↗

Returns nullopt if JSON parsing failed (e.g., broken surrogates)

Source from the content-addressed store, hash-verified

395
396// Returns nullopt if JSON parsing failed (e.g., broken surrogates)
397std::optional<std::variant<ada::url_pattern_init, ada::url_pattern_options>>
398parse_init(ondemand::object& object) {
399 ada::url_pattern_init init{};
400 for (auto field : object) {
401 auto key = field.key().value();
402 std::string_view value;
403 // Check if this is a boolean field (like ignoreCase) vs a string field
404 if (field.value().type() == ondemand::json_type::boolean) {
405 bool ignore_case = false;
406 EXPECT_FALSE(field.value().get_bool().get(ignore_case));
407 return ada::url_pattern_options{.ignore_case = ignore_case};
408 }
409 // For string fields, if get_string fails (e.g., broken surrogates),
410 // return nullopt to indicate the test should be skipped
411 if (field.value().get_string(value)) {
412 // String parsing failed - likely broken surrogates in JSON.
413 // simdjson strictly rejects unpaired surrogates, while browsers may
414 // convert them to replacement characters. Skip this test case.
415 return std::nullopt;
416 }
417 if (key == "protocol") {
418 init.protocol = std::string(value);
419 } else if (key == "username") {
420 init.username = std::string(value);
421 } else if (key == "password") {
422 init.password = std::string(value);
423 } else if (key == "hostname") {
424 init.hostname = std::string(value);
425 } else if (key == "port") {
426 init.port = std::string(value);
427 } else if (key == "pathname") {
428 init.pathname = std::string(value);
429 } else if (key == "search") {
430 init.search = std::string(value);
431 } else if (key == "hash") {
432 init.hash = std::string(value);
433 } else if (key == "baseURL") {
434 init.base_url = std::string(value);
435 }
436 }
437 return init;
438}
439
440ada::url_pattern_options parse_options(ondemand::object& object) {
441 ada::url_pattern_options options{};

Callers 3

parse_pattern_fieldFunction · 0.85
parse_inputs_arrayFunction · 0.85
parse_exec_resultFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected