Skip to content

wcurl: never derive an output filename of '-' - #106

Closed
vszakats wants to merge 1 commit into
curl:mainfrom
vszakats:fix-dash-derived-output-fn
Closed

vszakats wants to merge 1 commit into
curl:mainfrom
vszakats:fix-dash-derived-output-fn

Conversation

@vszakats

@vszakats vszakats commented Oct 7, 2026

Copy link
Copy Markdown
Member

get_url_filename() percent-decodes a URL's final path segment and uses
it verbatim as curl's --output argument. A URL whose path ends in '-'
(literally or as '%2D') therefore yields exactly '-', which curl
treats as a request to write to stdout instead of a file. wcurl then
streams the downloaded body to the terminal, where escape sequences in
the response could be interpreted by the terminal emulator.

Make get_url_filename() return an empty string instead of '-', so the
existing "no filename found" fallback in exec_curl() picks the default
'index.html' the same way it already does for URLs with no path.

Reported-by: Joshua Rogers

get_url_filename() percent-decodes a URL's final path segment and uses
it verbatim as curl's --output argument. A URL whose path ends in '-'
(literally or as '%2D') therefore yields exactly '-', which curl
treats as a request to write to stdout instead of a file. wcurl then
streams the downloaded body to the terminal, where escape sequences in
the response could be interpreted by the terminal emulator.

Make get_url_filename() return an empty string instead of '-', so the
existing "no filename found" fallback in exec_curl() picks the default
'index.html' the same way it already does for URLs with no path.

Reported-by: Joshua Rogers
@samueloph

Copy link
Copy Markdown
Collaborator

Could you add a few tests? This would suffice:

diff --git a/tests/tests.sh b/tests/tests.sh
--- a/tests/tests.sh
+++ b/tests/tests.sh
@@ -222,6 +222,28 @@ testUrlDefaultNameTrailingBackwardSlash()
     assertContains "Verify whether 'wcurl' chooses the correct default filename when there is no path in the URL and the URL ends with a backslash" "${ret}" 'index.html'
 }
 
+testUrlDefaultNameDash()
+{
+    url='example.com/-'
+    ret=$(${WCURL_CMD} ${url} 2>&1 | tr '\n' ' ')
+    assertContains "Verify whether 'wcurl' chooses the default filename when the filename in the URL is '-'" "${ret}" '--output index.html '
+
+    url='example.com/%2D'
+    ret=$(${WCURL_CMD} ${url} 2>&1 | tr '\n' ' ')
+    assertContains "Verify whether 'wcurl' chooses the default filename when the filename in the URL is a percent-encoded '-'" "${ret}" '--output index.html '
+
+    url='example.com/-'
+    ret=$(${WCURL_CMD} --no-decode-filename ${url} 2>&1 | tr '\n' ' ')
+    assertContains "Verify whether 'wcurl' chooses the default filename when the filename in the URL is '-' and --no-decode-filename is used" "${ret}" '--output index.html '
+}
+
+testUrlAllowDashWhenOutput()
+{
+    url='example.com/filename'
+    ret=$(${WCURL_CMD} ${url} -o - 2>&1 | tr '\n' ' ')
+    assertContains "Verify whether 'wcurl' allows writing to stdout when the output path is set by the user" "${ret}" '--output - '
+}
+
 testUrlDecodingWhitespace()
 {
     url='example.com/filename%20with%20spaces'

Comment thread wcurl.md

## * Use 'index.html' as the default filename
if there is none in the URL.
if there is none in the URL, or if it is '-'.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you update the README file and manpage as well?

@vszakats

Copy link
Copy Markdown
Member Author

It's not my patch, perhaps it was a mistake to just forward it like this.
Closing.

@vszakats vszakats closed this Oct 12, 2026
@vszakats
vszakats deleted the fix-dash-derived-output-fn branch October 12, 2026 08:23
@samueloph

Copy link
Copy Markdown
Collaborator

It's not my patch, perhaps it was a mistake to just forward it like this.

No, you did the right thing, I don't mind making the changes myself if you're not available.

I've merged this as 8a1d388.

Thank you

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.

3 participants