Skip to content

fix(router-macro): omit ? and stray & when query arguments are empty - #5845

Open
nicoburns wants to merge 1 commit into
mainfrom
devin/1789562167-router-query-no-dangling-qmark
Open

nicoburns wants to merge 1 commit into
mainfrom
devin/1789562167-router-query-no-dangling-qmark

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

Fixes #5792. Closes #5839 (supersedes it with an allocation-free approach).

Routable's generated Display impl unconditionally wrote ? before the query segment, so a route like /doc/:id?:folder with folder: None rendered as /doc/abc?. It also wrote & after every non-empty, non-final argument regardless of what followed, so /r?:a&:b with a: Some(1), b: None rendered as /r?a=1&.

The generated code now tracks a single bool and emits the separator lazily, only in front of arguments that actually produced output:

let mut wrote_query_argument = false;
// per `:arg`
let as_string = DisplayQueryArgument::new("arg", arg).to_string(); // pre-existing alloc
if !as_string.is_empty() {
    f.write_str(if wrote_query_argument { "&" } else { "?" })?;
    write!(f, "{}", utf8_percent_encode(&as_string, QUERY_ASCII_SET))?;
    wrote_query_argument = true;
}

The ?:..params (FullQuerySegment) path gets the same is_empty() guard. No new allocations; the trailing parameter on QueryArgument::write is gone since position no longer matters.

Test covers the full-query path, plus a two-argument route with every combination of present/absent arguments, round-tripping through from_str.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/2a0f4275713d441fb98a3b8b8d7f63a4
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/2a0f4275713d441fb98a3b8b8d7f63a4?variant=devin-insiders
Requested by: @nicoburns

@staging-devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'DevinAI' or '@devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

This branch has not been deployed

No deployments
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.

Router routes with query segments serialize a trailing ? even when the query is empty

1 participant