Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3e36512
Fix eval string handling to handle strings containing single and doub…
brunk Dec 5, 2019
943308f
Add tests for to handling strings containing single and double quotes.
brunk Dec 5, 2019
2b84e28
Fixed recent shellcheck errors.
kward Feb 11, 2020
001b248
Merged from GitHub.
kward Mar 29, 2020
73f27f8
Updated from upstream.
kward Mar 29, 2020
fe964fe
Starting a new 1.2.4 release series.
kward Mar 29, 2020
5cb3d86
Removed blank line.
kward Mar 29, 2020
ef6f50e
Fixing merge issue.
brunk Apr 27, 2020
4a44939
Fixed by rebasing on upstream.
kward Mar 29, 2020
b24adf8
Fixed expr command determination to work with 'set -e'.
kward Apr 9, 2020
ab09d52
Pulled latest from upstream.
kward Apr 9, 2020
a202774
Refactored logging code and fixed some 'set -e' issues.
kward Apr 9, 2020
59aaaa6
Removed line limit restrictions.
kward Apr 9, 2020
6cda74b
Setup repo hooks.
kward Apr 10, 2020
3c5fc95
Fixed 'set -e' errors.
kward Apr 10, 2020
71db95d
Fixes to hooks.
kward Apr 10, 2020
28832e2
Fixes to hooks.
kward Apr 10, 2020
edc1844
Fixes to hooks.
kward Apr 10, 2020
81722e3
Merged public and issue_28 tests. Fixed test errors.
kward Mar 29, 2020
0a50d86
Run with multiple linux distros.
kward Apr 10, 2020
32c85b2
Updated from upstream.
kward Mar 29, 2020
d031fa8
Fixed shellcheck errors.
kward Apr 10, 2020
a9d47d6
Fixed recent test failures, and a shunit2 bug.
kward Mar 29, 2020
b53d925
Try testing with multiple linux distros.
kward Apr 10, 2020
e39b814
Reworked to fix test failures on both macOS and Linux.
kward Mar 29, 2020
cf2b337
Don't test 16.04 twice.
kward Apr 10, 2020
4b9a380
Fixed ShellCheck warnings.
kward Mar 29, 2020
0ac7dff
Trying to figure out where the test_runner is failing.
kward Apr 10, 2020
059b27f
Fixed ShellCheck warnings.
kward Mar 29, 2020
08f3100
Replaced tabs with spaces.
kward Apr 10, 2020
15fe2c7
Limit which branches and tags will be tested.
kward Mar 29, 2020
9487873
Added testing of mksh.
kward Apr 10, 2020
887af19
Pulled from upstream.
kward Apr 11, 2020
208aea8
Fix warning for shells that aren't passing.
kward Apr 10, 2020
170a05a
Merge branch 'master' of github.com:kward/shflags
kward Apr 11, 2020
94bbf55
Pulled from upstream.
kward Apr 11, 2020
3eab942
Modernized the testGetoptStandard function.
kward Apr 11, 2020
757447b
Modernized the testGetoptStandard function.
kward Apr 11, 2020
4379bf2
Removed unused TH_MY_NAME variable.
kward Apr 11, 2020
2ad6555
Fixed minor shell nit.
kward Apr 10, 2020
f39d119
Enabled "set -e" by default.
kward Apr 11, 2020
cdeae63
Merge branch 'master' of github.com:kward/shflags
kward Apr 11, 2020
aa2aeaa
Merge branch 'master' of github.com:kward/shflags
kward Apr 11, 2020
800dbce
Fixes to th_showOutput().
kward Apr 11, 2020
c254393
More set -e fixes.
kward Apr 11, 2020
0c6cef6
Removed unused variable.
kward Apr 11, 2020
9c82dec
Fixed more set -e errors.
kward Apr 11, 2020
dcaf009
Fixed shellcheck errors.
kward Apr 11, 2020
5a8c0d6
Fixed bug that allowed bad commit to succeed.
kward Apr 11, 2020
3f7f9c0
Fixed more set -e issues.
kward Apr 11, 2020
e598075
Fixed handling of deleted files.
kward Apr 12, 2020
aba0a5b
Pulled from upstream.
kward Apr 13, 2020
0d478a3
Fixed #50. FLAGS_ARGC is no longer exported. Started 1.4.0pre series.
kward Apr 13, 2020
2508002
Fixed a couple of potential set -e stragglers.
kward Apr 13, 2020
4d44106
Reformatted.
kward Apr 13, 2020
5fd87fe
Reformatted.
kward Apr 13, 2020
28a8d15
Reformatted.
kward Apr 13, 2020
d7c5971
Renamed to CHANGES-1.3.md.
kward Apr 13, 2020
66427f9
Removed FLAGS_ARGC harder.
kward Apr 13, 2020
d3e6545
Removed FLAGS_ARGC harder.
kward Apr 13, 2020
ca7e8a7
Test with Ubuntu Trusty as well.
kward Apr 13, 2020
a8adcc2
Merge branch 'master' of https://github.com/kward/shflags
brunk Apr 27, 2020
5a661c2
Reimplement proper escaping for options and arguments.
brunk Apr 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions shflags
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ _flags_parseGetopt() {
;;

${__FLAGS_TYPE_STRING})
eval "FLAGS_${_flags_usName_}='${_flags_arg_}'"
eval "FLAGS_${_flags_usName_}=\${_flags_arg_}"
;;
esac

Expand All @@ -894,7 +894,7 @@ _flags_parseGetopt() {
# Give user back non-flag arguments.
FLAGS_ARGV=''
while [ $# -gt 0 ]; do
FLAGS_ARGV="${FLAGS_ARGV:+${FLAGS_ARGV} }'$1'"
FLAGS_ARGV="${FLAGS_ARGV:+${FLAGS_ARGV} } `_flags_escape "$1"`"
shift
done

Expand All @@ -903,6 +903,13 @@ _flags_parseGetopt() {
return ${flags_return}
}

_flags_escape() {
[ -n "${BASH_VERSION:-}" ] && printf "%q\n" "$1" && return 0
[ -n "${ZSH_VERSION:-}" ]&& printf "%q\n" "$1" && return 0
[ -n "${KSH_VERSION:-}" ]&& printf "%q\n" "$1" && return 0
printf "%s\n" "$1" | sed -e "s/'/'\"'\"'/g" -e "1s/^/'/" -e "\$s/\$/'/"
}

# Perform some path using built-ins.
#
# Args:
Expand Down
99 changes: 99 additions & 0 deletions shflags_parsing_quotes_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#! /bin/sh
# vim:et:ft=sh:sts=2:sw=2
#
# shFlags unit test for the flag definition methods
#
# Copyright 2008-2017 Kate Ward. All Rights Reserved.
# Released under the Apache 2.0 license.
#
# Author: kate.ward@forestent.com (Kate Ward)
# https://github.com/kward/shflags
#
### ShellCheck (http://www.shellcheck.net/)
# Disable source following.
# shellcheck disable=SC1090,SC1091

# TODO(kward): assert on FLAGS errors
# TODO(kward): testNonStandardIFS()

# Exit immediately if a pipeline or subshell exits with a non-zero status.
#set -e

# Treat unset variables as an error.
set -u

# These variables will be overridden by the test helpers.
returnF="${TMPDIR:-/tmp}/return"
stdoutF="${TMPDIR:-/tmp}/STDOUT"
stderrF="${TMPDIR:-/tmp}/STDERR"

# Load test helpers.
. ./shflags_test_helpers

testOptionStringsWithQuotes() {
_testValidOptionStrings -s "Single Quote Flag's Test"
_testValidOptionStrings -s "Double Quote \"Flag\" Test"
_testValidOptionStrings -s "Mixed Quote's \"Flag\" Test"
_testValidOptionStrings -s 'Mixed Quote'\''s "Flag" Test'
}

testArgumentStringsWithQuotes() {
_testValidArgumentStrings "Single Quote Flag's Test"
_testValidArgumentStrings "Double Quote \"Flag\" Test"
_testValidArgumentStrings "Mixed Quote's \"Flag\" Test"
}

_testValidOptionStrings() {
flag=$1
value=$2

FLAGS "${flag}" "${value}" >"${stdoutF}" 2>"${stderrF}"
r3turn=$?
assertTrue "'FLAGS ${flag} ${value}' returned a non-zero result (${r3turn})" \
${r3turn}
# shellcheck disable=SC2154
assertEquals "string (${value}) test failed." "${value}" "${FLAGS_str}"
if [ ${r3turn} -eq "${FLAGS_TRUE}" ]; then
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
else
# Validate that an error is thrown for unsupported getopt uses.
assertFatalMsg '.* spaces in options'
fi
th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
}

_testValidArgumentStrings() {
quoted_string="$1"
FLAGS "$quoted_string" >"${stdoutF}" 2>"${stderrF}"
r3turn=$?
assertTrue "'FLAGS $quoted_string' returned a non-zero result (${r3turn})" \
${r3turn}
eval set -- "${FLAGS_ARGV}"
assertEquals "$quoted_string" "$1"
}

oneTimeSetUp() {
th_oneTimeSetUp

if flags_getoptIsStd; then
th_warn 'Standard version of getopt found. Enhanced tests will be skipped.'
else
th_warn 'Enhanced version of getopt found. Standard tests will be skipped.'
fi
}

setUp() {
DEFINE_boolean bool false 'boolean test' 'b'
DEFINE_float float 0.0 'float test' 'f'
DEFINE_integer int 0 'integer test' 'i'
DEFINE_string str '' 'string test' 's'
}

tearDown() {
flags_reset
}

# Load and run shUnit2.
# shellcheck disable=SC2034
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
. "${TH_SHUNIT}"