#220: Handle escaped quotes in tags database file.

If there are escaped quotes in the tags database file, when the file is read,
then written, additional escape characters were inserted.

For example:

When tag 'a "test"' is written, it gets stored as 'a \"test\"'. Then it's read
back in that form, but the next time it's serialized to disk, the quotes would
be escaped again resulting in 'a \\"test\\"' which has the effect of removing
the escapes for the double-quotes.
This commit is contained in:
Shaun Ruffell 2019-11-13 06:13:47 -06:00 committed by lauft
parent 5f5cfb7b0f
commit 8109c155af
2 changed files with 9 additions and 1 deletions

View file

@ -29,6 +29,7 @@
#include <JSON.h>
#include <iostream>
#include <iomanip>
#include <shared.h>
#include <timew.h>
////////////////////////////////////////////////////////////////////////////////
@ -287,7 +288,7 @@ void Database::initializeTagDatabase ()
for (auto &pair : json->_data)
{
auto key = pair.first;
auto key = str_replace (pair.first, "\\\"", "\"");
auto *value = (json::object *) pair.second;
auto iter = value->_data.find ("count");

View file

@ -255,6 +255,13 @@ class TestTag(TestCase):
self.t("stop")
self.t("delete @1")
def test_tag_with_double_quote(self):
"""Call 'tag' with an embedded double quote sign"""
code, out, err = self.t("start 'this is a \"test\"'")
self.assertIn("Note: '\"this is a \\\"test\\\"\"' is a new tag", out)
self.t("stop")
self.t("delete @1")
if __name__ == "__main__":
from simpletap import TAPTestRunner