Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trurl: run --trim query before --append query #225

Merged
merged 1 commit into from
Aug 7, 2023

Conversation

emanuele6
Copy link
Collaborator

@emanuele6 emanuele6 commented Jun 22, 2023

Before this patch there was not a way to add a query parameter to a URL, removing the previous value if the parameter was already present in the base URL.

I tried to use:

x () {
  trurl --verify --trim query=foo --append "query=foo=$2" -- "$1"
}

But that didn't work since --trim query runs after --append query, so the new value value added with --append also gets trimmed:

$ x 'https://example.org/?foo=hello&baz=boo' 'howdy'
https://example.org/?baz=boo

This patch makes trurl run --trim before --append so that using --trim query=foo --append query=foo=bar works to set foo to bar overwriting previous values of foo.

$ x 'https://example.org/?foo=hello&baz=boo' 'howdy'
https://example.org/?baz=boo&foo=howdy

I added a test for this, and I also added a test that tests that --sort-query and --append query work together, since I noticed it was missing.

Before this patch there was not a way to add a query parameter to a URL,
removing the previous value if the parameter was already present in the
base URL.

I tried to use:

  x () {
    trurl --verify --trim query=foo --append "query=foo=$2" -- "$1"
  }

But that didn't work since  --trim query  runs after --append query, so
the new value value added with --append also gets trimmed:

  $ x 'https://example.org/?foo=hello&baz=boo' 'howdy'
  https://example.org/?baz=boo

This patch makes trurl run  --trim  before  --append  so that using
--trim query=foo --append query=foo=bar  works to set foo to bar
overwriting previous values of foo.

  $ x 'https://example.org/?foo=hello&baz=boo' 'howdy'
  https://example.org/?baz=boo&foo=howdy

I added a test for this, and I also added a test that tests that
--sort-query  and  --append query  work together, since I noticed it was
missing.
Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

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

Fair!

@bagder bagder merged commit 1e83ccc into curl:master Aug 7, 2023
@emanuele6 emanuele6 deleted the trimbefore branch August 7, 2023 12:03
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.

2 participants