Skip to content

Commit

Permalink
base64 encode document ids that contain a period. fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Aug 30, 2019
1 parent d3c4cbd commit 311807c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/assets/javascripts/services/ratingsStoreSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// sent down from the backend. It comes in when the query
// is initially retrieved and managed here.
//
// For documents whose id is a simple string, we pass that
// back and forth. However, if the id of the document is
// a URL or contains a "." character, then we do escaping.
//
angular.module('QuepidApp')
.service('ratingsStoreSvc', [
'$http',
Expand All @@ -19,8 +23,7 @@ angular.module('QuepidApp')

var path = function(docId) {
var id = docId;

if ( /http/.test(docId) ) {
if ( /http/.test(docId) || /\./.test(docId)) {
id = btoa(docId);
}

Expand Down
16 changes: 16 additions & 0 deletions spec/javascripts/angular/services/ratingsStoreSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ describe('Service: Ratingsstoresvc', function () {
expect(ratingsStore.getRating('file://foo/bar')).toBe(10);
$httpBackend.verifyNoOutstandingExpectation();
});
it('should base 64 and urlencode when POSTIng rating w id is URL', function() {
var ratingsStore = ratingsStoreSvc.createRatingsStore(0, 1, {});
$httpBackend.expectPUT('/api/cases/0/queries/1/ratings/aHR0cDovL3d3dy5leGFtcGxlLmNvbS9kb2MvMQ%3D%3D').respond(200, {});
ratingsStore.rateDocument('http://www.example.com/doc/1', 10);
$httpBackend.flush();
expect(ratingsStore.getRating('http://www.example.com/doc/1')).toBe(10);
$httpBackend.verifyNoOutstandingExpectation();
});
it('should base 64 and urlencode when POSTIng rating w id containing a period', function() {
var ratingsStore = ratingsStoreSvc.createRatingsStore(0, 1, {});
$httpBackend.expectPUT('/api/cases/0/queries/1/ratings/bXlkb2MucGRm').respond(200, {});
ratingsStore.rateDocument('mydoc.pdf', 10);
$httpBackend.flush();
expect(ratingsStore.getRating('mydoc.pdf')).toBe(10);
$httpBackend.verifyNoOutstandingExpectation();
});

it('should urlencode when DELETING rating', function() {
var ratingsStore = ratingsStoreSvc.createRatingsStore(0, 1, {});
Expand Down

0 comments on commit 311807c

Please sign in to comment.