This repository was archived by the owner on May 20, 2024. It is now read-only.
File tree 4 files changed +79
-1
lines changed
4 files changed +79
-1
lines changed Original file line number Diff line number Diff line change 23
23
# shellcheck source=basic/chkcmd.inc.sh
24
24
. " $INCLUDE_PSST /basic/chkcmd.inc.sh"
25
25
26
+ # shellcheck source=basic/esc.inc.sh
27
+ . " $INCLUDE_PSST /basic/esc.inc.sh"
28
+
26
29
# shellcheck source=basic/conv.inc.sh
27
30
. " $INCLUDE_PSST /basic/conv.inc.sh"
28
31
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env sh
2
+
3
+ # Double include protection
4
+ case " $INCLUDE_SEEN_PSST " in
5
+ * _esc.inc.sh_* )
6
+ return
7
+ ;;
8
+ esac
9
+ INCLUDE_SEEN_PSST=" $INCLUDE_SEEN_PSST _esc.inc.sh_"
10
+
11
+
12
+ # shellcheck source=assert.inc.sh
13
+ . " $INCLUDE_PSST /basic/assert.inc.sh"
14
+
15
+
16
+ # #
17
+ # SUBPROCESS
18
+ # esc_for_sq_psst <value>
19
+ #
20
+ # SUMMARY
21
+ # Escapes `value` so it can be safely used within single quotes. This
22
+ # means it only escapes single quotes themselves as all other characters,
23
+ # including backshlash, are safe to be used within single quotes. Basically
24
+ # `abc'def'`` becomes `abc'\''def`.
25
+ #
26
+ #
27
+ # PARAMETERS
28
+ # value: Value to be escaped for usage within single quotes.
29
+ #
30
+ # OUTPUT
31
+ # stdout: The escaped value.
32
+ #
33
+ # SAMPLE
34
+ # safeValue=$( esc_for_sq_psst "$value" )
35
+ #
36
+ esc_for_sq_psst ()
37
+ (
38
+ value=$1
39
+
40
+ func=" esc_for_sq_psst"
41
+ assert_argc_psst " $func " 1 $#
42
+
43
+ printf " %s" " $value " | sed " s/'/'\\ \''/g"
44
+ )
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env sh
2
+
3
+ # Exit at once if a command fails and the error isn't caught
4
+ set -e
5
+
6
+ if [ -z " $INCLUDE_PSST " ]
7
+ then
8
+ cmdBase=$( dirname " $0 " )
9
+ INCLUDE_PSST=" $cmdBase /../../../lib/psst"
10
+ fi
11
+
12
+ # shellcheck source=../../../lib/psst/basic.inc.sh
13
+ . " $INCLUDE_PSST /basic.inc.sh"
14
+
15
+ # =============================================================================
16
+ # esc_for_sq
17
+
18
+ # Must accept exactly one argument
19
+ set +e
20
+ ( esc_for_sq_psst 2> /dev/null )
21
+ [ $? = 127 ] || test_fail_psst $LINENO
22
+
23
+ ( esc_for_sq_psst 1 2 2> /dev/null )
24
+ [ $? = 127 ] || test_fail_psst $LINENO
25
+ set -e
26
+
27
+
28
+ # Test the encoding
29
+ [ " $( esc_for_sq_psst " " ) " = " " ] || test_fail_psst $LINENO
30
+ [ " $( esc_for_sq_psst " abc" ) " = " abc" ] || test_fail_psst $LINENO
31
+ [ " $( esc_for_sq_psst " ab'cd" ) " = " ab'\\ ''cd" ] || test_fail_psst $LINENO
32
+ [ " $( esc_for_sq_psst " 'a'b" ) " = " '\\ ''a'\\ ''b" ] || test_fail_psst $LINENO
Original file line number Diff line number Diff line change 31
31
set -e
32
32
33
33
34
-
35
34
# Test push, pop
36
35
oldIFS=" $IFS "
37
36
You can’t perform that action at this time.
0 commit comments