Skip to content

urlapi: consume trailing dots after IPv4 numerical addresses#21635

Closed
bagder wants to merge 3 commits into
masterfrom
bagder/url-ip4-trailingdot
Closed

urlapi: consume trailing dots after IPv4 numerical addresses#21635
bagder wants to merge 3 commits into
masterfrom
bagder/url-ip4-trailingdot

Conversation

@bagder

@bagder bagder commented May 15, 2026

Copy link
Copy Markdown
Member

If the hostname is specified as an IPv4 numerical address and it is followed by a single dot, acccept that as a valid IPv4 and remove the dot when normalizing.

This prevents otherwise legitimate IPv4 hostnames to have trailing dots. Seems to match what browsers do.

Extended test 1560 to verify.

If the hostname is specified as an IPv4 numerical address and it is
followed by a single dot, acccept that as a valid IPv4 and remove the
dot when normalizing.

This prevents otherwise legitimate IPv4 hostnames to have trailing dots.
Seems to match what browsers do.

Extended test 1560 to verify.
@bagder bagder added the URL label May 15, 2026
@github-actions github-actions Bot added the tests label May 15, 2026
@bagder bagder marked this pull request as ready for review May 15, 2026 20:48
@bagder bagder requested a review from Copilot May 15, 2026 20:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Allows a single trailing dot after IPv4 numerical addresses in URLs and normalizes them by stripping the dot, matching browser behavior. Previously, such inputs were left unchanged (e.g., 0111.02.0x3. was kept as-is instead of being normalized to 73.2.0.3).

Changes:

  • In ipv4_normalize(), when number parsing returns STRE_NO_NUM and we're at end-of-string after at least one part was parsed, the trailing empty part is consumed (n--) rather than rejected.
  • When the 4th part is followed by a single trailing . with nothing after it, parsing completes successfully instead of failing.
  • Updated two existing test cases (no longer keep trailing dot) and added 11 new test cases covering various IPv4 trailing-dot scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/urlapi.c Modify ipv4_normalize() to accept and swallow a single trailing dot after numerical IPv4 addresses; update docstring.
tests/libtest/lib1560.c Update two existing expected outputs and add tests covering trailing-dot IPv4 normalization and rejection of double trailing dots.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bagder bagder closed this in 831a151 May 15, 2026
@bagder bagder deleted the bagder/url-ip4-trailingdot branch May 15, 2026 21:39
outcast36 pushed a commit to greearb/curl that referenced this pull request Jun 3, 2026
If the hostname is specified as an IPv4 numerical address and it is
followed by a single dot, acccept that as a valid IPv4 and remove the
dot when normalizing.

This prevents otherwise legitimate IPv4 hostnames to have trailing dots.
Seems to match what browsers do.

Extended test 1560 to verify.

Closes curl#21635
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants