Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0628d62

Browse files
giftigdjc
authored andcommitted
Unit test for doc IDs with unsafe characters
Specifically a slash.
1 parent 0f4835e commit 0628d62

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

couchdb/tests/couch_tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,31 @@ def test_utf8_encoding(self):
191191
for idx, row in enumerate(self.db.query(query)):
192192
self.assertEqual(texts[idx], row.key)
193193

194+
def test_update_with_unsafe_doc_ids(self):
195+
doc_id = 'sanitise/the/doc/id/plz/'
196+
design_doc = 'test_slashes_in_doc_ids'
197+
handler_name = 'test'
198+
func = """
199+
function(doc, req) {
200+
doc.test = 'passed';
201+
return [doc, 'ok'];
202+
}
203+
"""
204+
205+
# Stick an update handler in
206+
self.db['_design/%s' % design_doc] = {
207+
'updates': {handler_name: func}
208+
}
209+
# And a test doc
210+
self.db[doc_id] = {'test': 'failed'}
211+
212+
response = self.db.update_doc(
213+
'%s/%s' % (design_doc, handler_name),
214+
docid=doc_id
215+
)
216+
217+
self.assertEqual(self.db[doc_id]['test'], 'passed')
218+
194219
def test_design_docs(self):
195220
for i in range(50):
196221
self.db[str(i)] = {'integer': i, 'string': str(i)}

0 commit comments

Comments
 (0)