Changeset 366


Ignore:
Timestamp:
12/16/10 13:23:10 (14 years ago)
Author:
lgiessmann
Message:

TM-SPARQL: fixed a problem in all filter statements that uses """, ' or and do not escape inner " in literals

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/TM-SPARQL/sparql_filter.lisp

    r365 r366  
    5959  ;; *replace function(x), function(x, y), function(x, y, z)
    6060  ;;   by filter-function(x), (filter-function(x, y), filter-function(x, y, z)
    61   ;; check if all functions that will e invoked are allowed
     61  ;; check if all functions that will be invoked are allowed
     62  ;; add a let with all variables that are used: every variable with $ and ? prefix
     63  ;; add a let with (true t) and (false nil)
    6264  ;; *create and store this filter object
    6365
     
    122124             (list :next-query (string-after cleaned-str result)
    123125                   :scope result)))
    124           ((string-starts-with cleaned-str "'''")
     126          ((string-starts-with cleaned-str "\"")
    125127           (let ((result (get-literal cleaned-str)))
    126128             (list :next-query (getf result :next-query)
     
    349351
    350352
    351 (defun get-literal (query-string &key (quotation "'''"))
     353(defun get-literal (query-string &key (quotation "\""))
    352354  "Returns a list of the form (:next-query <string> :literal <string>
    353355   where next-query is the query after the found literal and literal
     
    367369             (string-starts-with query-string "'"))
    368370         (let ((literal-end
    369                 (find-literal-end (subseq query-string 1)(subseq query-string 0 1))))
     371                (find-literal-end (subseq query-string 1)
     372                                  (subseq query-string 0 1))))
    370373           (when literal-end
    371              (list :next-query (subseq query-string (+ 1 literal-end))
    372                    :literal (concatenate 'string quotation
    373                                          (subseq query-string 1 literal-end)
    374                                          quotation)))))))
     374             (let ((literal
     375                    (escape-string (subseq query-string 1 literal-end) "\"")))
     376               (list :next-query (subseq query-string (+ 1 literal-end))
     377                     :literal (concatenate 'string quotation literal
     378                                           quotation))))))))
    375379
    376380
  • TabularUnified trunk/src/base-tools/base-tools.lisp

    r364 r366  
    3030           :string-after-number
    3131           :separate-leading-digits
    32            :white-space))
     32           :white-space
     33           :escape-string))
    3334
    3435(in-package :base-tools)
     
    262263      (and position-of-colon (> position-of-colon 0)
    263264           (not (find #\/ (subseq uri 0 position-of-colon)))))))
     265
     266
     267(defun escape-string (str char-to-escape)
     268  "Escapes every occurrence of char-to-escape in str, if it is
     269   not escaped."
     270  (declare (String str char-to-escape))
     271  (let ((result ""))
     272    (dotimes (idx (length str))
     273      (let ((current-char (subseq str idx (1+ idx)))
     274            (previous-char (if (= idx 0) "" (subseq str (1- idx) idx))))
     275        (cond ((and (string= current-char char-to-escape)
     276                    (string/= previous-char "\\"))
     277               (push-string "\\" result)
     278               (push-string current-char result))
     279              (t
     280               (push-string current-char result)))))
     281    result))
  • TabularUnified trunk/src/unit_tests/sparql_test.lisp

    r365 r366  
    10601060    (is-true result-2)
    10611061    (is (string= (getf result-1 :filter-string)
    1062                  "BOUND((progn   (progn ?var)  )) || (progn isLITERAL($var) && ?var = '''abc''')"))
     1062                 "BOUND((progn   (progn ?var)  )) || (progn isLITERAL($var) && ?var = \"abc\")"))
    10631063    (is (string= (getf result-1 :next-query) "}"))
    10641064    (is (string= (getf result-2 :filter-string)
    1065                  "(progn REGEX(?var1, '''''', ?var3) || (progn ?var1 > ?var3 && (progn STR( ?var) = '''abc''')))"))
     1065                 "(progn REGEX(?var1, \"\", ?var3) || (progn ?var1 > ?var3 && (progn STR( ?var) = \"abc\")))"))
    10661066    (is (string= (getf result-2 :next-query) "}"))
    10671067    (is (string= (getf result-3 :filter-string)
     
    10821082         (str-2 "!BOUND(?var1) = false}")
    10831083         (str-3 "+?var1=-$var2}")
    1084          (str-4 "!'abc' && (+12 = - 14)}")
     1084         (str-4 "!'a\"b\"c' && (+12 = - 14)}")
    10851085         (result-1
    10861086          (getf (tm-sparql::set-boundings dummy-object str-1) :filter-string))
     
    11101110    (is (string= result-2-1 "(not BOUND(?var1)) = false"))
    11111111    (is (string= result-3-1 "(1+ ?var1)=(1- $var2)"))
    1112     (is (string= result-4-1 "(not '''abc''') && (progn (1+ 12) = (1- 14))"))))
     1112    (is (string= result-4-1 "(not \"a\\\"b\\\"c\") && (progn (1+ 12) = (1- 14))"))))
    11131113         
    11141114
Note: See TracChangeset for help on using the changeset viewer.