[tracker/wip/carlosg/fix-tracker-search: 9/11] libtracker-data: Convert arguments to string in string functions
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/fix-tracker-search: 9/11] libtracker-data: Convert arguments to string in string functions
- Date: Sat, 17 Nov 2018 15:29:26 +0000 (UTC)
commit fc16c98e8eaa6c4067ab8264d232a655f82103d2
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Nov 17 15:35:55 2018 +0100
libtracker-data: Convert arguments to string in string functions
This results in eg. URN strings or ISO8601 dates being passed to
those if used in one such function, instead of ROWIDs or timestamps.
It's unclear how that should behave as per the spec, this is however
what the old parser did, so better to stick to the same implementation
defined behavior.
src/libtracker-data/tracker-sparql.c | 41 +++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index e32a4f2b0..1627486cd 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -4966,6 +4966,8 @@ handle_type_cast (TrackerSparql *sparql,
const gchar *function,
GError **error)
{
+ sparql->current_state.convert_to_string = TRUE;
+
if (g_str_equal (function, XSD_NS "string")) {
_append_string (sparql, "CAST (");
_call_rule (sparql, NAMED_RULE_ArgList, error);
@@ -4995,14 +4997,17 @@ handle_xpath_function (TrackerSparql *sparql,
{
if (g_str_equal (function, FN_NS "lower-case")) {
_append_string (sparql, "SparqlLowerCase (");
+ sparql->current_state.convert_to_string = TRUE;
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
} else if (g_str_equal (function, FN_NS "upper-case")) {
_append_string (sparql, "SparqlUpperCase (");
+ sparql->current_state.convert_to_string = TRUE;
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
} else if (g_str_equal (function, FN_NS "contains")) {
/* contains('A','B') => 'A' GLOB '*B*' */
+ sparql->current_state.convert_to_string = TRUE;
_step (sparql);
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "(");
@@ -5021,6 +5026,7 @@ handle_xpath_function (TrackerSparql *sparql,
* 0010fffd always sorts last.
*/
+ sparql->current_state.convert_to_string = TRUE;
_step (sparql);
_append_string (sparql, "( ");
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
@@ -5042,6 +5048,7 @@ handle_xpath_function (TrackerSparql *sparql,
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_BOOLEAN;
} else if (g_str_equal (function, FN_NS "ends-with")) {
/* strends('A','B') => 'A' GLOB '*B' */
+ sparql->current_state.convert_to_string = TRUE;
_step (sparql);
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "(");
@@ -5054,6 +5061,7 @@ handle_xpath_function (TrackerSparql *sparql,
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_BOOLEAN;
} else if (g_str_equal (function, FN_NS "substring")) {
_append_string (sparql, "SUBSTR (");
+ sparql->current_state.convert_to_string = TRUE;
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_STRING;
@@ -5061,10 +5069,12 @@ handle_xpath_function (TrackerSparql *sparql,
const gchar *old_sep;
old_sep = tracker_sparql_swap_current_expression_list_separator (sparql, " || ");
+ sparql->current_state.convert_to_string = TRUE;
_call_rule (sparql, NAMED_RULE_ArgList, error);
tracker_sparql_swap_current_expression_list_separator (sparql, old_sep);
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_STRING;
} else if (g_str_equal (function, FN_NS "string-join")) {
+ sparql->current_state.convert_to_string = TRUE;
_append_string (sparql, "SparqlStringJoin (");
_step (sparql);
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
@@ -5083,6 +5093,7 @@ handle_xpath_function (TrackerSparql *sparql,
_append_string (sparql, ") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_STRING;
} else if (g_str_equal (function, FN_NS "replace")) {
+ sparql->current_state.convert_to_string = TRUE;
_append_string (sparql, "SparqlReplace (");
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
@@ -5183,6 +5194,7 @@ handle_custom_function (TrackerSparql *sparql,
TrackerParserNode *node;
if (g_str_equal (function, TRACKER_NS "case-fold")) {
+ sparql->current_state.convert_to_string = TRUE;
_append_string (sparql, "SparqlCaseFold (");
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
@@ -5190,14 +5202,17 @@ handle_custom_function (TrackerSparql *sparql,
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, "COLLATE " TRACKER_TITLE_COLLATION_NAME " ");
} else if (g_str_equal (function, TRACKER_NS "ascii-lower-case")) {
+ sparql->current_state.convert_to_string = TRUE;
_append_string (sparql, "lower (");
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
} else if (g_str_equal (function, TRACKER_NS "normalize")) {
+ sparql->current_state.convert_to_string = TRUE;
_append_string (sparql, "SparqlNormalize (");
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
} else if (g_str_equal (function, TRACKER_NS "unaccent")) {
+ sparql->current_state.convert_to_string = TRUE;
_append_string (sparql, "SparqlUnaccent (");
_call_rule (sparql, NAMED_RULE_ArgList, error);
_append_string (sparql, ") ");
@@ -5280,7 +5295,10 @@ handle_function_call (TrackerSparql *sparql,
GError **error)
{
gchar *function = _dup_last_string (sparql);
- gboolean handled;
+ gboolean handled, convert_to_string;
+
+ convert_to_string = sparql->current_state.convert_to_string;
+ sparql->current_state.convert_to_string = FALSE;
if (g_str_has_prefix (function, XSD_NS)) {
handled = handle_type_cast (sparql, function, error);
@@ -5300,6 +5318,7 @@ handle_function_call (TrackerSparql *sparql,
}
}
+ sparql->current_state.convert_to_string = convert_to_string;
g_free (function);
return handled;
@@ -5408,8 +5427,12 @@ static gboolean
translate_BuiltInCall (TrackerSparql *sparql,
GError **error)
{
+ gboolean convert_to_string;
const gchar *old_sep;
+ convert_to_string = sparql->current_state.convert_to_string;
+ sparql->current_state.convert_to_string = FALSE;
+
if (_check_in_rule (sparql, NAMED_RULE_Aggregate)) {
_call_rule (sparql, NAMED_RULE_Aggregate, error);
} else if (_check_in_rule (sparql, NAMED_RULE_RegexExpression)) {
@@ -5465,6 +5488,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_CLOSE_PARENS);
_append_string (sparql, ") ");
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_STRLEN)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "LENGTH (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5472,12 +5496,14 @@ translate_BuiltInCall (TrackerSparql *sparql,
_append_string (sparql, ") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_INTEGER;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_UCASE)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlUpperCase (");
_call_rule (sparql, NAMED_RULE_Expression, error);
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_CLOSE_PARENS);
_append_string (sparql, ") ");
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_LCASE)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlLowerCase (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5519,6 +5545,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_TZ)) {
_unimplemented ("TZ");
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_MD5)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlChecksum (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5526,6 +5553,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_append_string (sparql, ", \"md5\") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_STRING;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_SHA1)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlChecksum (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5533,6 +5561,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_append_string (sparql, ", \"sha1\") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_STRING;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_SHA256)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlChecksum (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5540,6 +5569,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_append_string (sparql, ", \"sha256\") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_STRING;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_SHA384)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlChecksum (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5547,6 +5577,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_append_string (sparql, ", \"sha384\") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_STRING;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_SHA512)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlChecksum (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5581,6 +5612,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_unimplemented ("LANGMATCHES");
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_CONTAINS)) {
/* contains('A','B') => 'A' GLOB '*B*' */
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "(");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5597,6 +5629,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
/* strstarts('A','B') => 'A' BETWEEN 'B' AND 'B\u0010fffd'
* 0010fffd always sorts last.
*/
+ sparql->current_state.convert_to_string = TRUE;
_append_string (sparql, "( ");
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5617,6 +5650,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_BOOLEAN;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_STRENDS)) {
/* strends('A','B') => 'A' GLOB '*B' */
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "(");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5627,6 +5661,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_append_string (sparql, ") ");
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_BOOLEAN;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_STRBEFORE)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlStringBefore (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5636,6 +5671,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_CLOSE_PARENS);
_append_string (sparql, ") ");
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_STRAFTER)) {
+ sparql->current_state.convert_to_string = TRUE;
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "SparqlStringAfter (");
_call_rule (sparql, NAMED_RULE_Expression, error);
@@ -5697,6 +5733,7 @@ translate_BuiltInCall (TrackerSparql *sparql,
_expect (sparql, RULE_TYPE_TERMINAL, TERMINAL_TYPE_NIL);
_unimplemented ("STRUUID");
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_CONCAT)) {
+ sparql->current_state.convert_to_string = TRUE;
old_sep = tracker_sparql_swap_current_expression_list_separator (sparql, " || ");
_call_rule (sparql, NAMED_RULE_ExpressionList, error);
tracker_sparql_swap_current_expression_list_separator (sparql, old_sep);
@@ -5708,6 +5745,8 @@ translate_BuiltInCall (TrackerSparql *sparql,
tracker_sparql_swap_current_expression_list_separator (sparql, old_sep);
}
+ sparql->current_state.convert_to_string = convert_to_string;
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]