[evolution/gnome-3-30] I#107 - Reply with selection and URL can produce extra letters
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-30] I#107 - Reply with selection and URL can produce extra letters
- Date: Wed, 12 Sep 2018 11:56:15 +0000 (UTC)
commit 2e87004096f2bf7d6456d7a5dd78dfd5b3f37e22
Author: Milan Crha <mcrha redhat com>
Date: Wed Sep 5 11:19:52 2018 +0200
I#107 - Reply with selection and URL can produce extra letters
Closes https://gitlab.gnome.org/GNOME/evolution/issues/107
src/e-util/test-html-editor-units-bugs.c | 68 ++++++++++++++++++++++
.../web-extension/e-editor-dom-functions.c | 61 ++++++-------------
2 files changed, 87 insertions(+), 42 deletions(-)
---
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index 3837927657..c7f669d18d 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -1388,6 +1388,73 @@ test_issue_103 (TestFixture *fixture)
#undef LONG_URL
}
+static void
+test_issue_107 (TestFixture *fixture)
+{
+ if (!test_utils_process_commands (fixture,
+ "mode:plain\n")) {
+ g_test_fail ();
+ return;
+ }
+
+ test_utils_insert_content (fixture,
+ "<pre>text\n"
+ "<a href=\"https://www.01.org/\">https://www.01.org/</a> ?\n"
+ "<a href=\"https://www.02.org/\">https://www.02.org/</a> A\n"
+ "<a href=\"https://www.03.org/\">https://www.03.org/</a> ěšč\n"
+ "<a href=\"https://www.04.org/\">https://www.04.org/</a> ?\n"
+ "<a href=\"https://www.05.org/\">https://www.05.org/</a>\n"
+ "<a href=\"https://www.06.org/\">https://www.06.org/</a> \n"
+ "<a href=\"https://www.07.org/\">https://www.07.org/</a>  \n"
+ "<a href=\"https://www.08.org/\">https://www.08.org/</a> > < \n"
+ "<<a href=\"https://www.09.org/\">https://www.09.org/</a>>\n"
+ "<<a href=\"https://www.10.org/\">https://www.10.org/</a> ?>\n"
+ " <a href=\"https://www.11.org/\">https://www.11.org/</a> \n"
+ "< <a href=\"https://www.12.org/\">https://www.12.org/</a> >\n"
+ " <<a href=\"https://www.13.org/\">https://www.13.org/</a>> \n</pre>"
+ "<span class=\"-x-evo-to-body\" data-credits=\"On Today, User wrote:\"></span>"
+ "<span class=\"-x-evo-cite-body\"></span>",
+ E_CONTENT_EDITOR_INSERT_REPLACE_ALL | E_CONTENT_EDITOR_INSERT_TEXT_HTML);
+
+ if (!test_utils_run_simple_test (fixture,
+ "",
+ HTML_PREFIX
+ "<div style=\"width: 71ch;\">On Today, User wrote:</div>"
+ "<blockquote type=\"cite\" " BLOCKQUOTE_STYLE ">"
+ "<div style=\"width: 71ch;\">> text</div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.01.org/\">https://www.01.org/</a> ?</div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.02.org/\">https://www.02.org/</a> A</div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.03.org/\">https://www.03.org/</a> ěšč</div>"
+ "<div style=\"width: 71ch;\">> <a href=\"https://www.04.org/\">https://www.04.org/</a>
?</div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.05.org/\">https://www.05.org/</a></div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.06.org/\">https://www.06.org/</a> </div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.07.org/\">https://www.07.org/</a> </div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.08.org/\">https://www.08.org/</a> > < </div>"
+ "<div style=\"width: 71ch;\">> <<a
href=\"https://www.09.org/\">https://www.09.org/</a>></div>"
+ "<div style=\"width: 71ch;\">> <<a
href=\"https://www.10.org/\">https://www.10.org/</a> ?></div>"
+ "<div style=\"width: 71ch;\">> <a
href=\"https://www.11.org/\">https://www.11.org/</a> </div>"
+ "<div style=\"width: 71ch;\">> < <a
href=\"https://www.12.org/\">https://www.12.org/</a> ></div>"
+ "<div style=\"width: 71ch;\">> <<a
href=\"https://www.13.org/\">https://www.13.org/</a>> </div>"
+ "</blockquote>" HTML_SUFFIX,
+ "On Today, User wrote:\n"
+ "> text\n"
+ "> https://www.01.org/ ?\n"
+ "> https://www.02.org/ A\n"
+ "> https://www.03.org/ ěšč\n"
+ "> https://www.04.org/ ?\n"
+ "> https://www.05.org/\n"
+ "> https://www.06.org/ \n"
+ "> https://www.07.org/ \n"
+ "> https://www.08.org/ > < \n"
+ "> <https://www.09.org/>\n"
+ "> <https://www.10.org/ ?>\n"
+ "> https://www.11.org/ \n"
+ "> < https://www.12.org/ >\n"
+ "> <https://www.13.org/> ")) {
+ g_test_fail ();
+ }
+}
+
void
test_add_html_editor_bug_tests (void)
{
@@ -1419,4 +1486,5 @@ test_add_html_editor_bug_tests (void)
test_utils_add_test ("/bug/750636", test_bug_750636);
test_utils_add_test ("/issue/86", test_issue_86);
test_utils_add_test ("/issue/103", test_issue_103);
+ test_utils_add_test ("/issue/107", test_issue_107);
}
diff --git a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index ff92ddc9c2..098daafdcd 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -4952,8 +4952,7 @@ create_anchor_for_link (const GMatchInfo *info,
GString *res,
gpointer data)
{
- gboolean link_surrounded, ending_with_nbsp = FALSE;
- gint offset = 0, truncate_from_end = 0;
+ gint offset = 0, truncate_from_end = 0, match_len;
gint match_start, match_end;
gchar *match;
const gchar *end_of_match = NULL;
@@ -4962,15 +4961,21 @@ create_anchor_for_link (const GMatchInfo *info,
match = g_match_info_fetch (info, 0);
g_match_info_fetch_pos (info, 0, &match_start, &match_end);
- if (g_str_has_suffix (match, " ")) {
- ending_with_nbsp = TRUE;
- truncate_from_end = 6;
+ match_len = strlen (match);
+ end_of_match = match + match_end - match_start - 1;
+ while (truncate_from_end + 4 < match_len) {
+ if (truncate_from_end + 6 < match_len && g_ascii_strncasecmp (match + match_end - match_start
- truncate_from_end - 6, " ", 6) == 0) {
+ truncate_from_end += 6;
+ end_of_match -= 6;
+ } else if (g_ascii_strncasecmp (match + match_end - match_start - truncate_from_end - 4,
"<", 4) == 0 ||
+ g_ascii_strncasecmp (match + match_end - match_start - truncate_from_end - 4,
">", 4) == 0) {
+ truncate_from_end += 4;
+ end_of_match -= 4;
+ } else {
+ break;
+ }
}
- if (g_str_has_prefix (match, " "))
- offset += 6;
-
- end_of_match = match + match_end - match_start - 1;
/* Taken from camel-url-scanner.c */
/* URLs are extremely unlikely to end with any punctuation, so
* strip any trailing punctuation off from link and put it after
@@ -4981,35 +4986,13 @@ create_anchor_for_link (const GMatchInfo *info,
}
end_of_match++;
- link_surrounded =
- g_str_has_suffix (res->str, "<");
-
- if (link_surrounded) {
- if (end_of_match && *end_of_match && strlen (match) > strlen (end_of_match) + 3)
- link_surrounded = link_surrounded && g_str_has_prefix (end_of_match - 3, ">");
- else
- link_surrounded = link_surrounded && g_str_has_suffix (match, ">");
-
- if (link_surrounded) {
- truncate_from_end += 4;
- end_of_match -= 4;
- }
- }
-
- /* The ending ';' was counted when looking for the invalid trailing characters, substract it. */
- if (link_surrounded || ending_with_nbsp) {
- truncate_from_end -= 1;
- end_of_match += 1;
- }
-
/* If there is non-breaking space in the match, remove it and everything
* after it from the match */
- if (!g_str_has_prefix (match, " ") && !g_str_has_suffix (match, " ") && (nbsp_match =
strstr (match, " "))) {
- glong after_nbsp_length = g_utf8_strlen (nbsp_match, -1);
+ if (!g_str_has_prefix (match, " ") && !g_str_has_suffix (match, " ") &&
+ (nbsp_match = strstr (match, " ")) && nbsp_match < end_of_match) {
+ glong after_nbsp_length = strlen (nbsp_match);
truncate_from_end = after_nbsp_length;
- end_of_match -= after_nbsp_length;
- if (link_surrounded)
- end_of_match += 4;
+ end_of_match = match + match_end - match_start - after_nbsp_length;
}
g_string_append (res, "<a href=\"");
@@ -5020,18 +5003,12 @@ create_anchor_for_link (const GMatchInfo *info,
g_string_truncate (res, res->len - truncate_from_end);
g_string_append (res, "\">");
- g_string_append (res, match + offset);
- if (truncate_from_end > 0)
- g_string_truncate (res, res->len - truncate_from_end);
-
+ g_string_append_len (res, match + offset, match_len - offset - (truncate_from_end > 0 ?
truncate_from_end : 0));
g_string_append (res, "</a>");
if (truncate_from_end > 0)
g_string_append (res, end_of_match);
- if (ending_with_nbsp)
- g_string_append (res, " ");
-
g_free (match);
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]