mirror of
git://sourceware.org/git/libabigail.git
synced 2025-01-18 23:30:45 +00:00
Escape all characters when reading a string in ini files
It turns out that when parsing foo = bar\[a-z\], the '[' and ']' characters where not being escaped while parsing the string "bar\[a-z\]". This patch fixes that. * src/abg-ini.cc (read_context::peek): Take an output parameter to tell the caller when this function escaped the returned character. Added an overload without this new parameter. (read_context::read_string): Accept all characters as part of the string. * tests/data/test-diff-suppr/test7-var-suppr-9.suppr: New test input. * tests/data/test-diff-suppr/test7-var-suppr-report-9.txt: New test reference output. * tests/data/Makefile.am: Add the files above to source distribution. * tests/test-diff-suppr.cc (in_out_spec): Run a new comparison of libtest7-var-suppr-v{0,1}.so this time using the new test7-var-suppr-9.suppr specification that exercices a string with the escaped characters that we were having difficulty with. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
parent
5fe6a7404b
commit
3e47efb112
@ -871,19 +871,43 @@ public:
|
||||
/// Also note that this function handles escaping using the '\'
|
||||
/// (backslash) character.
|
||||
///
|
||||
/// @param escaped This is an output parameter. It's set to true by
|
||||
/// this function if it escaped the peeked character. Otherwise,
|
||||
/// it's set to false.
|
||||
///
|
||||
/// @return peeked character.
|
||||
char
|
||||
peek()
|
||||
peek(bool& escaped)
|
||||
{
|
||||
if (!buf_.empty())
|
||||
return buf_.back();
|
||||
|
||||
escaped = false;
|
||||
char c = in_.peek();
|
||||
if (handle_escape(c, /*peek=*/true))
|
||||
put_back(c);
|
||||
{
|
||||
put_back(c);
|
||||
escaped = true;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/// @return the character that is going to be read by the next
|
||||
/// invocation of read_next_char().
|
||||
///
|
||||
/// Note that this function doesn't alter the input stream.
|
||||
///
|
||||
/// Also note that this function handles escaping using the '\'
|
||||
/// (backslash) character.
|
||||
///
|
||||
/// @return peeked character.
|
||||
char
|
||||
peek()
|
||||
{
|
||||
bool escaped = false;
|
||||
return peek(escaped);
|
||||
}
|
||||
|
||||
/// Get the next character of the input stream.
|
||||
///
|
||||
/// This function knows how to handles escaped characters from the
|
||||
@ -947,7 +971,7 @@ public:
|
||||
/// This function must be called whenever the low level character
|
||||
/// reading function encountered a backslash character ('\'). In
|
||||
/// that case, this function reads the subsequent characters from
|
||||
/// the input stream, sees if it needs to espace those and then
|
||||
/// the input stream, sees if it needs to escape them and then
|
||||
/// handles the escaping if need be. Otherwise, it does nothing.
|
||||
///
|
||||
/// This is a subroutine of the read_context::get() and
|
||||
@ -1319,22 +1343,28 @@ public:
|
||||
/// positive when passed to
|
||||
/// read_context::char_is_property_name_char().
|
||||
///
|
||||
/// Note that all escaped characters are suitable to be in a string.
|
||||
///
|
||||
/// @return the string read.
|
||||
string
|
||||
read_string()
|
||||
{
|
||||
int b = peek();
|
||||
bool escaped = false;
|
||||
int b = peek(escaped);
|
||||
if (!good())
|
||||
return "";
|
||||
|
||||
if (char_is_delimiter(b, /*include_white_space=*/false))
|
||||
if (!escaped && char_is_delimiter(b, /*include_white_space=*/false))
|
||||
// Empty property value. This is accepted.
|
||||
return "";
|
||||
|
||||
string v;
|
||||
for (b = peek(); good();b = peek())
|
||||
for (b = peek(escaped); good(); b = peek(escaped))
|
||||
{
|
||||
if (!char_is_property_value_char(b))
|
||||
// If the current character is not suitable to be a in string,
|
||||
// then we reached the end of the string. Note that espaced
|
||||
// characters are always suitable to be a string.
|
||||
if (!escaped && !char_is_property_value_char(b))
|
||||
break;
|
||||
char c = 0;
|
||||
assert(read_next_char(c));
|
||||
|
@ -620,6 +620,7 @@ test-diff-suppr/test7-var-suppr-5.suppr \
|
||||
test-diff-suppr/test7-var-suppr-6.suppr \
|
||||
test-diff-suppr/test7-var-suppr-7.suppr \
|
||||
test-diff-suppr/test7-var-suppr-8.suppr \
|
||||
test-diff-suppr/test7-var-suppr-9.suppr \
|
||||
test-diff-suppr/test7-var-suppr-report-0.txt \
|
||||
test-diff-suppr/test7-var-suppr-report-1.txt \
|
||||
test-diff-suppr/test7-var-suppr-report-2.txt \
|
||||
@ -629,6 +630,7 @@ test-diff-suppr/test7-var-suppr-report-5.txt \
|
||||
test-diff-suppr/test7-var-suppr-report-6.txt \
|
||||
test-diff-suppr/test7-var-suppr-report-7.txt \
|
||||
test-diff-suppr/test7-var-suppr-report-8.txt \
|
||||
test-diff-suppr/test7-var-suppr-report-9.txt \
|
||||
test-diff-suppr/test7-var-suppr-version-script \
|
||||
test-diff-suppr/libtest8-redundant-fn-v0.so \
|
||||
test-diff-suppr/libtest8-redundant-fn-v1.so \
|
||||
|
7
tests/data/test-diff-suppr/test7-var-suppr-9.suppr
Normal file
7
tests/data/test-diff-suppr/test7-var-suppr-9.suppr
Normal file
@ -0,0 +1,7 @@
|
||||
[suppress_function]
|
||||
# This one shouldn't catch anything, but it must be parsed fine.
|
||||
symbol_version_regexp = ^VERSION_\[0-9\]\\.\[0-9\]$
|
||||
|
||||
[suppress_variable]
|
||||
# This one should be parsed fine too.
|
||||
symbol_version_regexp = ^VERSION_\[0-9\]\\.\[0-9\]$
|
3
tests/data/test-diff-suppr/test7-var-suppr-report-9.txt
Normal file
3
tests/data/test-diff-suppr/test7-var-suppr-report-9.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Functions changes summary: 0 Removed, 0 Changed, 0 Added function
|
||||
Variables changes summary: 0 Removed, 0 Changed (2 filtered out), 0 Added variable
|
||||
|
@ -438,6 +438,16 @@ InOutSpec in_out_specs[] =
|
||||
"data/test-diff-suppr/test7-var-suppr-report-8.txt",
|
||||
"output/test-diff-suppr/test7-var-suppr-report-8.txt"
|
||||
},
|
||||
{
|
||||
"data/test-diff-suppr/libtest7-var-suppr-v0.so",
|
||||
"data/test-diff-suppr/libtest7-var-suppr-v1.so",
|
||||
"",
|
||||
"",
|
||||
"data/test-diff-suppr/test7-var-suppr-9.suppr",
|
||||
"--no-default-suppression --no-show-locs --no-redundant",
|
||||
"data/test-diff-suppr/test7-var-suppr-report-9.txt",
|
||||
"output/test-diff-suppr/test7-var-suppr-report-9.txt"
|
||||
},
|
||||
{
|
||||
"data/test-diff-suppr/libtest8-redundant-fn-v0.so",
|
||||
"data/test-diff-suppr/libtest8-redundant-fn-v1.so",
|
||||
|
Loading…
Reference in New Issue
Block a user