Index: openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl,v diff -u -N -r1.57.2.22 -r1.57.2.23 --- openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl 29 Mar 2021 08:34:19 -0000 1.57.2.22 +++ openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl 22 Jun 2021 17:34:28 -0000 1.57.2.23 @@ -172,23 +172,31 @@ # # Helper functions for hstore # + set ::xowiki::hstore::max_value_size [parameter::get_global_value \ + -package_key xowiki \ + -parameter hstore_max_value_size \ + -default 0] + ad_proc double_quote {value} { + + From hstore manual: "Double-quote keys and values that include + whitespace, commas, =s or >s. To include a double quote or a + backslash in a key or value, escape it with a backslash." + https://www.postgresql.org/docs/current/hstore.html + @return double_quoted value as appropriate for hstore } { - if {[regexp {[ ,\"\\=>\n\']} $value]} { - set value \"[string map [list \" \\\" \\ \\\\ ' ''] $value]\" + if {[regexp {[\s,\"\'\\=>]} $value]} { + return \"[string map [list \" \\\" \\ \\\\ ' ''] $value]\" } return $value } ad_proc dict_as_hkey {dict} { @return dict value in form of a hstore key. } { - set max_value_size [parameter::get_global_value \ - -package_key xowiki \ - -parameter hstore_max_value_size \ - -default 0] set keys {} + variable ::xowiki::hstore::max_value_size foreach {key value} $dict { set v [double_quote $value] if {$v eq "" Index: openacs-4/packages/xowiki/tcl/test/api-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/test/Attic/api-test-procs.tcl,v diff -u -N -r1.1.2.11 -r1.1.2.12 --- openacs-4/packages/xowiki/tcl/test/api-test-procs.tcl 21 Jun 2021 13:51:51 -0000 1.1.2.11 +++ openacs-4/packages/xowiki/tcl/test/api-test-procs.tcl 22 Jun 2021 17:34:28 -0000 1.1.2.12 @@ -117,10 +117,10 @@ Checks conversion from dict to hstorage keys with proper escaping } { - set dict {key1 value1 key2 a'b k'y value3 key4 1,2} + set dict {key1 value1 key2 a'b k'y value3 key4 1,2 c before\tafter d "hello world"} aa_equals "filter option_list with empty exclusion set" \ - [::xowiki::hstore::dict_as_hkey $dict] \ - {key1=>value1,key2=>"a''b","k''y"=>value3,key4=>"1,2"} + [::xowiki::hstore::dict_as_hkey $dict] \ + {key1=>value1,key2=>"a''b","k''y"=>value3,key4=>"1,2",c=>"before after",d=>"hello world"} } # # Local variables: