Skip to content

Use pathSegment(_:) for the remaining inline path encodings #112

Description

@Adron

Noted while doing #95 (see PR #111), which collapsed the query-value encoders. The path side has the
same shape and was deliberately left alone to keep that PR a single concern.

What's there

APIClientTransport.swift provides:

func pathSegment(_ segment: String) -> String {
    segment.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? segment
}

but roughly a dozen call sites still inline the same expression:

let encoded = id.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? id

Why this is lower priority than #95 was

These are correct as written. Unlike the query-value case, there is no latent bug here —
.urlPathAllowed is the right set for a path segment, and the inline form produces exactly what
pathSegment(_:) would. This is consistency and discoverability, not correctness.

The reason it is worth doing at all: with two near-identical idioms in the file, the next person
copying one has a coin-flip chance of reaching for the wrong one, and picking .urlQueryAllowed for
a query value is precisely the bug #95 just spent a PR removing. #111 put queryValue(_:) directly
beside pathSegment(_:) with a comment saying they are not interchangeable; converting the
stragglers makes the file self-consistent so the comment is reinforced rather than contradicted.

Build this

  • Replace inline .urlPathAllowed encodings of a path segment with pathSegment(_:).
  • Leave anything that is not a single path segment alone — if a call site is encoding a whole
    path or something with intentional slashes, pathSegment(_:) is the wrong tool and it should
    keep doing what it does, with a comment saying why.
  • No behaviour change. If any conversion changes a single byte on the wire, stop and say so —
    that would mean the two forms were not equivalent after all.

Acceptance criteria

  • No inline .urlPathAllowed path-segment encoding remains, or each survivor has a one-line
    comment explaining why it is not using the helper.
  • Suite green with no test changes needed — a pure refactor should not require them.

Files: Services/APIClient.swift and the APIClient+*.swift extensions.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtCleanup / dead code / correctness hygienews:papercutsW8 — small parity papercuts

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions