[go: nahoru, domu]

Skip to content

Commit

Permalink
format-string: Fix pairing escaping
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
  • Loading branch information
sardemff7 committed Aug 5, 2022
1 parent 2c760b1 commit 5b81aaf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/format-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ _nk_format_string_strchr_escape(gchar *s, gsize l, gunichar c, gunichar pair_c)
if ( wc == '\\' )
/* Escaping a backslash, avoid escaping the next char */
wc = '\0';
else if ( wc == c )
else if ( ( wc == c ) || ( wc == pair_c ) )
{
w = g_utf8_prev_char(w);
pc = wc;
Expand Down
48 changes: 48 additions & 0 deletions tests/format-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,54 @@ static const struct {
.result = "Some value"
}
},
{
.testpath = "/nkutils/format-string/bug/pairing/non-escaped-unpair",
.data = {
.identifier = '$',
.source = "${variable:+{}",
.data = {
{ .name = "variable", .content = "true" },
{ .name = NULL }
},
.result = "${variable:+{}"
}
},
{
.testpath = "/nkutils/format-string/bug/pairing/escaped-unpair",
.data = {
.identifier = '$',
.source = "${variable:+\\{}",
.data = {
{ .name = "variable", .content = "true" },
{ .name = NULL }
},
.result = "{"
}
},
{
.testpath = "/nkutils/format-string/bug/pairing/escaped-pair",
.data = {
.identifier = '$',
.source = "${variable:+\\{\\}}",
.data = {
{ .name = "variable", .content = "true" },
{ .name = NULL }
},
.result = "{}"
}
},
{
.testpath = "/nkutils/format-string/bug/pairing/unescaped-pair",
.data = {
.identifier = '$',
.source = "${variable:+{}}",
.data = {
{ .name = "variable", .content = "true" },
{ .name = NULL }
},
.result = "{}"
}
},
};

static GVariant *
Expand Down

0 comments on commit 5b81aaf

Please sign in to comment.