Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-5794

View parser returns JSON strings unescaped

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: view-engine
    • Security Level: Public
    • Labels:
      None

      Description

      Document editing is using the following url http://lh:9000/couchBase/default/_all_docs?skip=0&include_docs=true&limit=5&_=1341509643238

      it normally works except Steve has broken it on my box by uploading this:

      1. wget O -q 'http://lh:9000/couchBase/default/00000001' {"_id":"00000001","_rev":"2-00027be31890c78a0000000000000000","name":"steve \"yen\"","job":1,"$expiration":0,"$flags":0}

      And those quotes break all docs output massively:
      wget O -q 'http://lh:9000/couchBase/default/all_docs?skip=0&include_docs=true&limit=5&=1341509643238'
      {"total_rows":998000,"rows":[
      {"id":"00000001","key":"00000001","value":

      {"rev":"2-00027be31890c78a0000000000000000"}

      ,"doc":{"_id":"00000001","_rev":"2-00027be31890c78a0000000000000000","name":"steve "yen"","job":1,"$expiration":0,"$flags":0}},
      {"id":"00000002","key":"00000002","value":

      {"rev":"1-00027b84bccda3f10000000000000000"}

      ,"doc":{"_id":"00000002","_rev":"1-00027b84bccda3f10000000000000000","$expiration":0,"$flags":0}},
      {"id":"00000004","key":"00000004","value":

      {"rev":"1-00027b84bcc993a90000000000000000"}

      ,"doc":{"_id":"00000004","_rev":"1-00027b84bcc993a90000000000000000","$expiration":0,"$flags":0}},
      {"id":"00000006","key":"00000006","value":

      {"rev":"1-00027b84bcc9f7420000000000000000"}

      ,"doc":{"_id":"00000006","_rev":"1-00027b84bcc9f7420000000000000000","$expiration":0,"$flags":0}},
      {"id":"00000007","key":"00000007","value":

      {"rev":"1-00027b84bccc52730000000000000000"}

      ,"doc":{"_id":"00000007","_rev":"1-00027b84bccc52730000000000000000","$expiration":0,"$flags":0}}
      ]
      }

      As you can see quotes inside steve "yen" are not escaped properly

        Activity

        Hide
        FilipeManana Filipe Manana (Inactive) added a comment -

        Verified, thanks for this excellent find.

        It turns out that YAJL's stream parser unescapes strings before passing them to the callback.
        The only solution (inefficient) is call YAJL's helpers to explicitly escape the string again.

        Just sent a patch upstream to make it not unescape the string, and avoiding re-escaping it:

        https://github.com/lloyd/yajl/pull/81

        Will close this soon.

        Show
        FilipeManana Filipe Manana (Inactive) added a comment - Verified, thanks for this excellent find. It turns out that YAJL's stream parser unescapes strings before passing them to the callback. The only solution (inefficient) is call YAJL's helpers to explicitly escape the string again. Just sent a patch upstream to make it not unescape the string, and avoiding re-escaping it: https://github.com/lloyd/yajl/pull/81 Will close this soon.
        Hide
        FilipeManana Filipe Manana (Inactive) added a comment -
        Show
        FilipeManana Filipe Manana (Inactive) added a comment - Fix merged to master. http://review.couchbase.org/#change,17979
        Hide
        thuan Thuan Nguyen added a comment -

        Integrated in github-couchdb-preview #441 (See http://qa.hq.northscale.net/job/github-couchdb-preview/441/)
        MB-5794 View parser didn't preserve escaping in strings (Revision 588f33dc74366d0e601fed50e705cae788b0c098)

        Result = SUCCESS
        Filipe David Borba Manana :
        Files :

        • src/couch_view_parser/yajl/yajl_parse.h
        • src/couch_view_parser/yajl/yajl_parser.c
        • src/couch_view_parser/yajl/yajl.c
        • src/couch_view_parser/test/01-map-view.t
        • src/couch_view_parser/couch_view_parser.cc
        Show
        thuan Thuan Nguyen added a comment - Integrated in github-couchdb-preview #441 (See http://qa.hq.northscale.net/job/github-couchdb-preview/441/ ) MB-5794 View parser didn't preserve escaping in strings (Revision 588f33dc74366d0e601fed50e705cae788b0c098) Result = SUCCESS Filipe David Borba Manana : Files : src/couch_view_parser/yajl/yajl_parse.h src/couch_view_parser/yajl/yajl_parser.c src/couch_view_parser/yajl/yajl.c src/couch_view_parser/test/01-map-view.t src/couch_view_parser/couch_view_parser.cc

          People

          • Assignee:
            FilipeManana Filipe Manana (Inactive)
            Reporter:
            alkondratenko Aleksey Kondratenko (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Gerrit Reviews

              There are no open Gerrit changes