felixge/node-couchdb

Correctly encode document IDs

Closed this issue · 4 comments

jhs commented

(Thought I submitted this already but don't see it.)

Fetching documents with special characters does not work, particularly when a document ID has / in it. This is because node-couchdb simply forwards the document ID into httpClient, and the server will think it is a request for an attachment.

I will submit a patch however I am unsure which solution is best.

  1. In couchClient._queueRequest(), encode the path before making the request, i.e. encodeURIComponent(options.path)
  2. Find every query which is definitely not for an attachment and encodeURIComponent() at that point. Candidates:
    • Client.prototype.db's couchdb.request
    • Db.prototype.getDoc
    • Db.prototype.saveDoc
    • Db.prototype.removeDoc
    • Db.prototype.copyDoc (srcId and possibly destId, need to check)
    • Db.prototype.saveAttachment
    • Db.prototype.removeAttachment
    • Db.prototype.getAttachment
    • Db.prototype.view
  3. Something more advanced such as an option to _queueRequest to encode the path, default=true. Then getAttachment can set it to false

I think choice 1 would break getAttachment() but choice 2 is a comparatively larger patch. What do you think? Thanks.

jhs commented

Also I think new ensureDesignId() to support _design/app/jason, _design/app/tim, etc would become _design/app%2fjason, _design/app%2ftim, etc.

Sorry to let you know, but I have decided to no longer maintain this module. The main reason is that I currently don't have any active project involving couchdb whatsoever, so maintaining this module has become an unmanageable burden. That being said, if somebody is interested in becoming the maintainer, let me know.

jhs commented

Not a problem! I believe I have an internal Git fork so if I fix bugs I'll push into my github repo.

Hi. Well, I'm not deleting this repository anytime soon, I just won't have time to work on the module or to review and merge patches.