Skip to content

Commit 0b29f72

Browse files
committed
Don't percent-decode colons ":", and percent encode them when found
Windows has this fun thing called NTFS Streams, which can lead to the file contents being stored in an unusual place if the target contains colons (unusual place = NTFS file stream). This could also result in the file being stored at the root of some other mount point (e.g.: C:filename). Users can still avail of storing the file contents in a stream or in another mountpoints by explicitly choosing the output file name.
1 parent 57017b5 commit 0b29f72

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

tests/tests.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,27 @@ testUrlDecodingBackslashes()
207207
assertContains "Verify whether 'wcurl' successfully uses the default filename when the URL ends with a slash" "${ret}" '--output filename%5Cwith%2Fbackslashes%5c%2f'
208208
}
209209

210+
testUrlDecodingColon()
211+
{
212+
url='example.com/filename%3Awith%3Acolons%3a'
213+
ret=$(${WCURL_CMD} ${url} 2>&1 | tr '\n' ' ')
214+
assertContains "Verify whether 'wcurl' successfully uses the default filename when the URL ends with a slash" "${ret}" '--output filename%3Awith%3Acolons%3a'
215+
}
216+
217+
testUrlEncodeColon()
218+
{
219+
url='example.com/filename:with:colons:'
220+
ret=$(${WCURL_CMD} ${url} 2>&1 | tr '\n' ' ')
221+
assertContains "Verify whether 'wcurl' successfully uses the default filename when the URL ends with a slash" "${ret}" '--output filename%3Awith%3Acolons%3A'
222+
}
223+
224+
testUrlAllowColonWhenOutput()
225+
{
226+
url='example.com/filename:with:colons:'
227+
ret=$(${WCURL_CMD} ${url} -o "i:want:colons:here" 2>&1 | tr '\n' ' ')
228+
assertContains "Verify whether 'wcurl' successfully uses the default filename when the URL ends with a slash" "${ret}" '--output i:want:colons:here'
229+
}
230+
210231
# Test decoding a bunch of different languages (that do not use the latin
211232
# alphabet), we could split each language on its own test, but for now it
212233
# does not make a difference.

wcurl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ readonly PER_URL_PARAMETERS="\
118118
# characters.
119119
# 2F = /
120120
# 5C = \
121-
readonly UNSAFE_PERCENT_ENCODE="%2F %5C"
121+
# 3A = :
122+
readonly UNSAFE_PERCENT_ENCODE="%2F %5C %3A"
122123

123124
# Whether to invoke curl or not.
124125
DRY_RUN="false"
@@ -193,7 +194,8 @@ get_url_filename()
193194
# If what remains contains a slash, there is a path; return it percent-decoded.
194195
case "${hostname_and_path}" in
195196
# sed to remove everything preceding the last '/', e.g.: "example/something" becomes "something"
196-
*/*) percent_decode "$(printf %s "${hostname_and_path}" | sed -e 's,^.*/,,')" ;;
197+
# sed to also replace ':' with the percent_encoded %3A
198+
*/*) percent_decode "$(printf %s "${hostname_and_path}" | sed -e 's,^.*/,,' -e 's,:,%3A,g')" ;;
197199
esac
198200
# No slash means there was just a hostname and no path; return empty string.
199201
}

0 commit comments

Comments
 (0)