forked from att/ast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix expansion of multibyte IFS characters
Closes att#13. Previously, the `varsub` method used for the macro expansion of `$param`, `${param}`, and `${param op word}` would incorrectly expand the internal field separator (IFS) if it was a multibyte character. This was due to truncation based on the incorrect assumption that the IFS would never be larger than a single byte. This change fixes this issue by carefully tracking the number of bytes that should be persisted in the IFS case and ensuring that all bytes are written during expansion and substitution.
- Loading branch information
1 parent
82d686d
commit 4e0d6e3
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# These are the tests for the internal field separator (IFS). | ||
|
||
IFS=e | ||
set : : | ||
[[ "$*" == ":e:" ]] || log_error "IFS failed" ":e:" "$*" | ||
|
||
IFS='|' read first second third <<< 'one|two|three' | ||
[[ "${first}" -eq "one" ]] || log_error "IFS failed" "one" "${first}" | ||
[[ "${second}" -eq "two" ]] || log_error "IFS failed" "two" "${second}" | ||
[[ "${third}" -eq "three" ]] || log_error "IFS failed" "three" "${third}" | ||
|
||
# Multi-byte character checks will only work if UTF-8 inputs are enabled | ||
if [ "${LANG}" = "C.UTF-8" ] | ||
then | ||
# 2 byte latin accented e character | ||
IFS=é | ||
set : : | ||
[[ "$*" == ":é:" ]] || log_error "IFS failed with multibyte character" ":é:" "$*" | ||
|
||
# 4 byte roman sestertius character | ||
IFS=𐆘 read first second third <<< 'one𐆘two𐆘three' | ||
[[ "${first}" -eq "one" ]] || log_error "IFS failed" "one" "${first}" | ||
[[ "${second}" -eq "two" ]] || log_error "IFS failed" "two" "${second}" | ||
[[ "${third}" -eq "three" ]] || log_error "IFS failed" "three" "${third}" | ||
fi |