Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-nodejs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-nodejs
Commits
2bca4891
Unverified
Commit
2bca4891
authored
Mar 27, 2019
by
Jeremy Morrell
Committed by
GitHub
Mar 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix two issues with kvstore (#637)
parent
9fa61ce1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
3 deletions
+36
-3
kvstore.sh
lib/kvstore.sh
+11
-3
unit
test/unit
+20
-0
empty-line
test/unit-fixtures/kvstore/empty-line
+3
-0
no-new-line
test/unit-fixtures/kvstore/no-new-line
+2
-0
No files found.
lib/kvstore.sh
View file @
2bca4891
...
@@ -45,9 +45,17 @@ kv_keys() {
...
@@ -45,9 +45,17 @@ kv_keys() {
local
keys
=()
local
keys
=()
if
[[
-f
$f
]]
;
then
if
[[
-f
$f
]]
;
then
# get list of keys
# Iterate over each line, splitting on the '=' character
while
IFS
=
"="
read
-r
key value
;
do
#
# The || [[ -n "$key" ]] statement addresses an issue with reading the last line
# of a file when there is no newline at the end. This will not happen if the file
# is created with this module, but can happen if it is written by hand.
# See: https://stackoverflow.com/questions/12916352/shell-script-read-missing-last-line
while
IFS
=
"="
read
-r
key value
||
[[
-n
"
$key
"
]]
;
do
# if there are any empty lines in the store, skip them
if
[[
-n
$key
]]
;
then
keys+
=(
"
$key
"
)
keys+
=(
"
$key
"
)
fi
done
<
"
$f
"
done
<
"
$f
"
echo
"
${
keys
[@]
}
"
|
tr
' '
'\n'
|
sort
-u
echo
"
${
keys
[@]
}
"
|
tr
' '
'\n'
|
sort
-u
...
...
test/unit
View file @
2bca4891
...
@@ -108,6 +108,26 @@ testKeyValue() {
...
@@ -108,6 +108,26 @@ testKeyValue() {
assertEquals
""
"
$(
kv_list
$store
)
"
assertEquals
""
"
$(
kv_list
$store
)
"
}
}
testKeyValueNoNewLine
()
{
local
store
# use a fixture that does not have an empty line after the final entry
store
=
"
$(
pwd
)
/test/unit-fixtures/kvstore/no-new-line"
assertEquals
"
$(
printf
"%s
\n
"
a
=
b
b
=
c
)
"
"
$(
kv_list
$store
)
"
assertEquals
"
$(
printf
"%s
\n
"
a b
)
"
"
$(
kv_keys
$store
)
"
}
testKeyValueEmptyLine
()
{
local
store
# use a fixture that has an extra empty line
store
=
"
$(
pwd
)
/test/unit-fixtures/kvstore/empty-line"
assertEquals
"
$(
printf
"%s
\n
"
a
=
b
b
=
c
)
"
"
$(
kv_list
$store
)
"
assertEquals
"
$(
printf
"%s
\n
"
a b
)
"
"
$(
kv_keys
$store
)
"
}
testKeyValueEscaping
()
{
testKeyValueEscaping
()
{
local
store
=
$(
mktemp
)
local
store
=
$(
mktemp
)
...
...
test/unit-fixtures/kvstore/empty-line
0 → 100644
View file @
2bca4891
a=b
b=c
test/unit-fixtures/kvstore/no-new-line
0 → 100644
View file @
2bca4891
a=b
b=c
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment