mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
#254: quotes in annotations are not escaped
Escapes the quotes for the annotations in the data file, and when converting an interval to JSON. The quotes in the annotations were already dequoted in IntervalFactory::fromSerialization, so we only needed to quote the strings when serializing or dumping to JSON.
This commit is contained in:
parent
1d8b2aa042
commit
5f5cfb7b0f
2 changed files with 14 additions and 2 deletions
|
@ -89,7 +89,7 @@ std::string Interval::serialize () const
|
|||
if (! annotation.empty ())
|
||||
{
|
||||
out << (_tags.empty () ? " #" : "")
|
||||
<< " # \"" << annotation << "\"";
|
||||
<< " # \"" << escape (annotation, '"') << "\"";
|
||||
}
|
||||
|
||||
return out.str ();
|
||||
|
@ -138,7 +138,7 @@ std::string Interval::json () const
|
|||
out << ',';
|
||||
}
|
||||
|
||||
out << "\"annotation\":\"" << annotation << "\"";
|
||||
out << "\"annotation\":\"" << escape (annotation, '"') << "\"";
|
||||
}
|
||||
|
||||
out << "}";
|
||||
|
|
|
@ -178,6 +178,18 @@ class TestAnnotate(TestCase):
|
|||
self.assertEquals(len(j), 1)
|
||||
self.assertClosedInterval(j[0], expectedAnnotation="foo")
|
||||
|
||||
def test_annotate_with_embedded_quotes(self):
|
||||
"""Call 'annotate' with embedded quotes"""
|
||||
now_utc = datetime.now().utcnow()
|
||||
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||
|
||||
self.t("track {:%Y-%m-%dT%H:%M:%S}Z - {:%Y-%m-%dT%H:%M:%S}Z".format(one_hour_before_utc, now_utc))
|
||||
self.t("annotate @1 'bar \"foo\" bar'")
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEquals(len(j), 1)
|
||||
self.assertClosedInterval(j[0], expectedAnnotation='bar "foo" bar')
|
||||
|
||||
if __name__ == "__main__":
|
||||
from simpletap import TAPTestRunner
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue