Skip to content

Commit

Permalink
Merge branch 'riker09-feature/binary-pk'
Browse files Browse the repository at this point in the history
  • Loading branch information
dozoisch committed Oct 14, 2017
2 parents 8ea7746 + 658d3f0 commit e27a71c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,14 @@ exports.to_display = function (input) {
exports.stringDocIDs = function (input) {

// Turns {_bsontype: ' ObjectID', id:12345... } into a plain string
if (input && typeof input === 'object' && input._bsontype === 'ObjectID') {
return input.toString();
if (input && typeof input === 'object') {
switch (input._bsontype) {
case 'Binary':
return input.toJSON();
case 'ObjectID':
default:
return input.toString();
}
}

return input;
Expand Down
6 changes: 6 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ const router = function (config) {
try {
obj_id = new mongodb.ObjectID.createFromHexString(id);
} catch (err) {
try {
// Is it a GUID?
obj_id = new mongodb.Binary(new Buffer(id, 'base64'), 3);
} catch (err) {
// Silence GUID error as well
}
// Silence the error
}

Expand Down
2 changes: 1 addition & 1 deletion lib/views/document.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'layout.html' %}

{% block title %}{{ document._id|to_string }}{% endblock %}
{% block title %}{{ document._id|stringDocIDs|to_string }}{% endblock %}


{% block styles %}
Expand Down

0 comments on commit e27a71c

Please sign in to comment.