Skip to content

Keep host type in sync when replacing or inheriting hosts - #1377

Merged
anonrig merged 3 commits into
ada-url:mainfrom
perfloop-oss:perfloop-pr-open-sry3fzxkgz
Dec 3, 2026
Merged

anonrig merged 3 commits into
ada-url:mainfrom
perfloop-oss:perfloop-pr-open-sry3fzxkgz

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

set_host and set_hostname can replace an IP host while leaving its classification as IPv4 or IPv6; relative resolution can inherit an IP host but report DEFAULT. This change keeps host_type in sync with the host in both ada::url and ada::url_aggregator, including callers of ada_get_host_type in the C API.

For example, setting the host of http://127.0.0.1/path to example.com produces http://example.com/path while still reporting IPV4. With this change, host_type reports DEFAULT, matching a fresh parse of the resulting URL after either setter.

The setters reset host_type to DEFAULT when a domain or opaque host is accepted, and when they clear the host. File URLs also get DEFAULT when localhost is normalized to an empty host. Setting an IPv4 or IPv6 host still leaves host_type as IPV4 or IPV6. Failed setters leave the existing host_type untouched.

Relative resolution now copies the classification together with the base host at all four state-machine copy sites.

tests/basic_tests.cpp covers both setters and representations, including file localhost, rejected mutations, and relative resolution with IPv4/IPv6 HTTP and file bases. Both typed tests fail on main before this change for each URL type.

CTest passed all 447 tests, with 0 failures and 0 skipped.

cc @anonrig @lemire

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.41%. Comparing base (361e649) to head (daf1003).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1377      +/-   ##
==========================================
+ Coverage   65.34%   65.41%   +0.06%     
==========================================
  Files          43       43              
  Lines        8926     8937      +11     
  Branches     3986     3986              
==========================================
+ Hits         5833     5846      +13     
  Misses        799      799              
+ Partials     2294     2292       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}

inline void url_aggregator::update_base_hostname(const std::string_view input) {
host_type = DEFAULT;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: url_aggregator::update_base_hostname now resets host_type, but its ada::url counterpart (include/ada/url-inl.h:131, inline void url::update_base_hostname(std::string_view input) { host = input; }) does not. It's harmless today because the only caller (src/parser.cpp, empty host in the HOST state) runs while host_type is still DEFAULT, but a future caller on an ada::url holding an IPv4/IPv6 host would leave host_type stale — the same kind of mismatch this PR fixes.

Adding host_type = DEFAULT; to url::update_base_hostname would close it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll add the same DEFAULT reset to url::update_base_hostname, keeping the existing tests and checking its empty-host parser path along with host mutation and relative resolution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added host_type = DEFAULT; before the host assignment in url::update_base_hostname, matching the aggregator helper. The existing tests are unchanged; all 447 CTest tests pass, as do formatting and static analysis.

@anonrig
anonrig merged commit 1943a71 into ada-url:main Dec 3, 2026
52 checks passed
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.

3 participants