Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libconfig
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
libconfig
Commits
9ad6ee70
Unverified
Commit
9ad6ee70
authored
Nov 14, 2017
by
Mark Lindner
Committed by
GitHub
Nov 14, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #90 from btmcg/master
Safely handle escape sequences
parents
0b221135
248dc6dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
0 deletions
+63
-0
lib/strbuf.c
lib/strbuf.c
+1
-0
tests/testdata/strings.cfg
tests/testdata/strings.cfg
+10
-0
tests/tests.c
tests/tests.c
+52
-0
No files found.
lib/strbuf.c
View file @
9ad6ee70
...
...
@@ -68,6 +68,7 @@ void strbuf_append_char(strbuf_t *buf, char c)
strbuf_ensure_capacity
(
buf
,
1
);
*
(
buf
->
string
+
buf
->
length
)
=
c
;
++
(
buf
->
length
);
*
(
buf
->
string
+
buf
->
length
)
=
'\0'
;
}
/* ------------------------------------------------------------------------- */
tests/testdata/strings.cfg
0 → 100644
View file @
9ad6ee70
escape_seqs:
{
str = "abc";
newline = "abc\ndef\n";
cr = "abc\rdef\r";
tab = "abc\tdef\t";
feed = "abc\fdef\f";
backslash = "abc\\def\\";
dquote = "abc\"def\"";
};
tests/tests.c
View file @
9ad6ee70
...
...
@@ -437,6 +437,57 @@ TT_TEST(RemoveSetting)
/* ------------------------------------------------------------------------- */
TT_TEST
(
EscapedStrings
)
{
config_t
cfg
;
config_setting_t
*
rc
;
int
ok
;
const
char
*
str
;
config_init
(
&
cfg
);
config_set_include_dir
(
&
cfg
,
"./testdata"
);
ok
=
config_read_file
(
&
cfg
,
"testdata/strings.cfg"
);
if
(
!
ok
)
{
printf
(
"error: %s:%d
\n
"
,
config_error_text
(
&
cfg
),
config_error_line
(
&
cfg
));
}
TT_ASSERT_TRUE
(
ok
);
ok
=
config_lookup_string
(
&
cfg
,
"escape_seqs.str"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"abc"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"escape_seqs.newline"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"abc
\n
def
\n
"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"escape_seqs.cr"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"abc
\r
def
\r
"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"escape_seqs.tab"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"abc
\t
def
\t
"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"escape_seqs.feed"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"abc
\f
def
\f
"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"escape_seqs.backslash"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"abc
\\
def
\\
"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"escape_seqs.dquote"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"abc
\"
def
\"
"
,
str
);
config_destroy
(
&
cfg
);
}
/* ------------------------------------------------------------------------- */
int
main
(
int
argc
,
char
**
argv
)
{
int
failures
;
...
...
@@ -453,6 +504,7 @@ int main(int argc, char **argv)
TT_SUITE_TEST
(
LibConfigTests
,
BigInt6
);
TT_SUITE_TEST
(
LibConfigTests
,
BigInt7
);
TT_SUITE_TEST
(
LibConfigTests
,
RemoveSetting
);
TT_SUITE_TEST
(
LibConfigTests
,
EscapedStrings
);
TT_SUITE_RUN
(
LibConfigTests
);
failures
=
TT_SUITE_NUM_FAILURES
(
LibConfigTests
);
TT_SUITE_END
(
LibConfigTests
);
...
...
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