summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Dywan <christian@twotoasts.de>2019-03-28 20:51:22 +0100
committerGitHub <noreply@github.com>2019-03-28 20:51:22 +0100
commit80ca3040f612fb3d3f440da5af22120543677a3a (patch)
tree1054619a3d2f4bfbc7070ec2c973cc6791de4730
parent3b076e26ead96fd54e88d9952fd9b50c7a3e5c14 (diff)
downloadmidori-git-80ca3040f612fb3d3f440da5af22120543677a3a.tar.gz
Highlight suggestions before escaping markup (#306)
As observed in this error message: (midori:21053): Gtk-WARNING **: 00:24:55.956: Failed to set text '...' from markup due to error parsing markup: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity — escape ampersand as &amp; The problem is that the regex operates on an already escaped string and sometimes matches part of an entity. - Let's instead match on the original text/ key and escape the result. - For the sake of simplicty don't worry about rare multiple matches.
-rw-r--r--core/suggestion-row.vala32
1 files changed, 16 insertions, 16 deletions
diff --git a/core/suggestion-row.vala b/core/suggestion-row.vala
index e8027cde..385c7f28 100644
--- a/core/suggestion-row.vala
+++ b/core/suggestion-row.vala
@@ -13,8 +13,6 @@ namespace Midori {
[GtkTemplate (ui = "/ui/suggestion-row.ui")]
public class SuggestionRow : Gtk.ListBoxRow {
public DatabaseItem item { get; protected set; }
- string? escaped_uri = null;
- string? escaped_title = null;
public string? location { get; set; }
public Regex? regex { get; set; }
public string? key { get; set; }
@@ -53,20 +51,11 @@ namespace Midori {
// Double-check type for the sake of plugins
} else if (item is DatabaseItem) {
icon.uri = item.uri;
- escaped_title = item.title != null ? Markup.escape_text (item.title) : "";
- title.label = escaped_title;
- escaped_uri = Markup.escape_text (strip_uri_prefix (item.uri));
- uri.label = escaped_uri;
- notify["regex"].connect ((pspec) => {
- if (regex != null) {
- try {
- var highlight = "<b>\\1</b>";
- uri.label = regex.replace (escaped_uri, -1, 0, highlight);
- title.label = regex.replace (escaped_title, -1, 0, highlight);
- } catch (RegexError error) {
- debug ("Failed to apply regex: %s", error.message);
- }
- }
+ title.label = item.title != null ? render (item.title) : "";
+ uri.label = render (strip_uri_prefix (item.uri));
+ notify["key"].connect ((pspec) => {
+ title.label = item.title != null ? render (item.title) : "";
+ uri.label = render (strip_uri_prefix (item.uri));
});
}
// Delete button to remove suggestions from history
@@ -74,6 +63,17 @@ namespace Midori {
this.delete.clicked.connect (() => { item.delete.begin (); });
}
+ string render (string text) {
+ if (key != null && key[0] != '\0') {
+ int index = text.down ().index_of (key.down ());
+ if (index > -1) {
+ return Markup.printf_escaped ("%s<b>%s</b>%s",
+ text.substring (0, index), key, text.substring (index + key.length));
+ }
+ }
+ return Markup.escape_text (text);
+ }
+
string? strip_uri_prefix (string uri) {
bool is_http = uri.has_prefix ("http://") || uri.has_prefix ("https://");
if (is_http || uri.has_prefix ("file://")) {