Skip to content

refactor(ads-client): type ad URLs as URLs instead of strings - #7614

Merged
Almaju merged 2 commits into
mozilla:mainfrom
Almaju:ads-client-newtypes
Sep 24, 2026
Merged

Almaju merged 2 commits into
mozilla:mainfrom
Almaju:ads-client-newtypes

Conversation

@Almaju

@Almaju Almaju commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

url and image_url on the image, spoc and tile ad types were String. They come straight out of the MARS response, so nothing stopped a malformed value reaching the caller.

They're now Url on the wire types and AdsClientUrl on the uniffi records. AdCallbacks and MozAdsCallbacks already type their URL fields that way, so this applies the same choice to the ones that were missed.

One behaviour change: a malformed URL now fails deserialization instead of being passed through. There's a test for it.

No binding change. AdsClientUrl lowers to String and is already in the bindings via MozAdsCallbacks.

Pull Request checklist

  • Breaking changes: none, the fields still cross the FFI as strings.
  • Quality: fmt and clippy --all-targets -- -D warnings clean, 106 unit tests pass.
  • Tests: one new test for the malformed-URL case.
  • Changelog: entry under ### Ads-Client in v158.0, since the failure behaviour changes.
  • Dependencies: none added.

@Almaju
Almaju force-pushed the ads-client-newtypes branch from d5cda93 to 969652f Compare September 22, 2026 15:20
`url` and `image_url` on `AdImage`, `AdSpoc` and `AdTile`, and on their
`MozAds*` counterparts, were `String`. They come straight out of the MARS
response body, so nothing stopped a malformed value reaching the caller.

They are now `Url` on the wire types and `AdsClientUrl` on the uniffi
records, which parses them once where they enter the component. Both
types were already in use next door: `AdCallbacks` and `MozAdsCallbacks`
have typed their three URL fields this way from the start.

The one behaviour change is that a malformed URL now fails
deserialization, so the request errors instead of handing the caller a
string that is not a URL. Covered by a new test.

No binding change. `AdsClientUrl` is a uniffi `custom_type!` that lowers
to `String` and is already part of the generated bindings through
`MozAdsCallbacks`, so the fields still cross the FFI as strings.

Test fixtures use the existing `url!` macro, which validates at compile
time, so there are no new unwraps. The two contract-test assertions that
checked these fields were not blank now check `has_host()`, since a
parsed `Url` cannot be empty.

`fmt`, `clippy --all-targets -D warnings` and 106 unit tests are green.
@Almaju
Almaju force-pushed the ads-client-newtypes branch from 969652f to 6e67be9 Compare September 22, 2026 15:34
@jonesetc

Copy link
Copy Markdown
Member

I think this makes sense and fits with the callback urls already. Good to have consistency for things that must be valid to be usable for clients.

@Almaju
Almaju marked this pull request as ready for review September 24, 2026 15:25
@Almaju
Almaju requested a review from a team as a code owner September 24, 2026 15:25
@Almaju
Almaju requested review from thesuzerain and removed request for a team September 24, 2026 15:25
Keep url!() macro for typed URL fields in AdTile test fixtures (from
the ads-client URL typing refactor), while adopting the "tile" format
string from main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0174ZP6xEv5z8MkdQv1a2387
@Almaju
Almaju enabled auto-merge September 24, 2026 16:20
@Almaju
Almaju added this pull request to the merge queue Sep 24, 2026
Merged via the queue into mozilla:main with commit 74a44e2 Sep 24, 2026
15 checks passed
@Almaju
Almaju deleted the ads-client-newtypes branch September 24, 2026 16:39
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.

4 participants