[tomboy/gnome-2-30] [websync] Update regex to ensure note content is synchronized
- From: Sanford Armstrong <sharm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tomboy/gnome-2-30] [websync] Update regex to ensure note content is synchronized
- Date: Tue, 19 Oct 2010 22:25:09 +0000 (UTC)
commit ffdf4ac4c0a0fce5c9c3e56f3d406093e2715fa5
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date: Tue Oct 19 15:18:00 2010 -0700
[websync] Update regex to ensure note content is synchronized
Add unit tests demonstrating the problem; <note-content> elements
with unexpected attributes caused us to send empty content during
web sync.
This can happen when note XML is generated by alternative Tomboy
note clients like Gnote.
A better fix would be to stop using a regex to parse this data, but
fixing the regex seemed more appropriate for a stable bugfix release.
https://bugzilla.gnome.org/show_bug.cgi?id=632535
Tomboy/Addins/WebSyncService/NoteConvert.cs | 2 +-
.../WebSyncService/Tests/NoteConvertTests.cs | 24 +++++++++++++++++--
Tomboy/Synchronization/SyncManager.cs | 2 +-
3 files changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/Tomboy/Addins/WebSyncService/NoteConvert.cs b/Tomboy/Addins/WebSyncService/NoteConvert.cs
index 9af47bc..74969af 100644
--- a/Tomboy/Addins/WebSyncService/NoteConvert.cs
+++ b/Tomboy/Addins/WebSyncService/NoteConvert.cs
@@ -57,7 +57,7 @@ namespace Tomboy.WebSync
noteInfo.Tags.Add (tag.Name);
const string noteContentRegex =
- @"^<note-content(\s+version=""(?<contentVersion>[^""]*)"")?\s*((/>)|(>(?<innerContent>.*)</note-content>))$";
+ @"^<note-content([^>]+version=""(?<contentVersion>[^""]*)"")?[^>]*((/>)|(>(?<innerContent>.*)</note-content>))$";
Match m = Regex.Match (note.XmlContent, noteContentRegex, RegexOptions.Singleline);
Group versionGroup = m.Groups ["contentVersion"];
Group contentGroup = m.Groups ["innerContent"];
diff --git a/Tomboy/Addins/WebSyncService/Tests/NoteConvertTests.cs b/Tomboy/Addins/WebSyncService/Tests/NoteConvertTests.cs
index f409cc3..5f4f49a 100644
--- a/Tomboy/Addins/WebSyncService/Tests/NoteConvertTests.cs
+++ b/Tomboy/Addins/WebSyncService/Tests/NoteConvertTests.cs
@@ -78,9 +78,9 @@ namespace Tomboy.WebSync.Tests
public void ToNoteInfoTest ()
{
// Note content stress tests
- string [] titles = new string [15];
- string [] contents = new string [15];
- string [] expectedInfoContents = new string [15];
+ string [] titles = new string [18];
+ string [] contents = new string [18];
+ string [] expectedInfoContents = new string [18];
titles [0] = "(Untitled 238)";
contents [0] = @"<note-content version=""0.1"">
@@ -211,6 +211,24 @@ Describe your new note here.";
Describe your new note here.</note-content>";
expectedInfoContents [14] = @"Describe your new note here.";
+
+ titles [15] = "New Note 331";
+ contents [15] = @"<note-content xmlns:link=""http://beatniksoftware.com/tomboy/link"" xmlns:size=""http://beatniksoftware.com/tomboy/size"" version=""0.1"">New Note 331
+
+Describe your new note here.</note-content>";
+ expectedInfoContents [15] = @"Describe your new note here.";
+
+ titles [16] = "New Note 331";
+ contents [16] = @"<note-content xmlns:link=""http://beatniksoftware.com/tomboy/link"" version=""0.1"" xmlns:size=""http://beatniksoftware.com/tomboy/size"">New Note 331
+
+Describe your new note here.</note-content>";
+ expectedInfoContents [16] = @"Describe your new note here.";
+
+ titles [17] = "New Note 331";
+ contents [17] = @"<note-content version=""0.1"" xmlns:size=""http://beatniksoftware.com/tomboy/size"">New Note 331
+
+Describe your new note here.</note-content>";
+ expectedInfoContents [17] = @"Describe your new note here.";
for (int i =0; i < titles.Length; i++) {
diff --git a/Tomboy/Synchronization/SyncManager.cs b/Tomboy/Synchronization/SyncManager.cs
index 45166fd..019290c 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -881,7 +881,7 @@ namespace Tomboy.Sync
private string GetInnerContent (string fullContentElement)
{
const string noteContentRegex =
- @"^<note-content(\s+version=""(?<contentVersion>[^""]*)"")?\s*((/>)|(>(?<innerContent>.*)</note-content>))$";
+ @"^<note-content([^>]+version=""(?<contentVersion>[^""]*)"")?[^>]*((/>)|(>(?<innerContent>.*)</note-content>))$";
Match m = Regex.Match (fullContentElement, noteContentRegex, RegexOptions.Singleline);
Group contentGroup = m.Groups ["innerContent"];
if (!contentGroup.Success)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]