diff options
author | Lisa Junger <ljunger@thoughtworks.com> | 2015-01-06 16:30:57 +0100 |
---|---|---|
committer | Lisa Junger <ljunger@thoughtworks.com> | 2015-01-06 16:35:53 +0100 |
commit | 0ff59644d8e804bcab928d184b31a5e6cdc2f6ed (patch) | |
tree | b6f4cd6f9826ea2e9d9e6e4e485a0fb32b78451d | |
parent | 2c19e7acbfb238e4fcd17725142c7ae9c43a3a77 (diff) |
Issue #182: Escape special chars in tag list.
-rw-r--r-- | web-ui/app/js/services/mail_service.js | 2 | ||||
-rw-r--r-- | web-ui/app/js/tags/ui/tag.js | 19 | ||||
-rw-r--r-- | web-ui/test/spec/services/mail_service.spec.js | 2 |
3 files changed, 19 insertions, 4 deletions
diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js index 24bceb31..2e92f542 100644 --- a/web-ui/app/js/services/mail_service.js +++ b/web-ui/app/js/services/mail_service.js @@ -184,7 +184,7 @@ define( }; function escaped(s) { - return encodeURI(s); + return encodeURIComponent(s); } this.excludeTrashedEmailsForDraftsAndSent = function (query) { diff --git a/web-ui/app/js/tags/ui/tag.js b/web-ui/app/js/tags/ui/tag.js index a77155a7..0d2d2ebf 100644 --- a/web-ui/app/js/tags/ui/tag.js +++ b/web-ui/app/js/tags/ui/tag.js @@ -43,7 +43,7 @@ define( this.viewFor = function (tag, template) { return template({ tagName: tag.default ? i18n('tags.' + tag.name) : tag.name, - ident: tag.ident, + ident: this.hashIdent(tag.ident), count: this.badgeType(tag) === 'total' ? tag.counts.total : (tag.counts.total - tag.counts.read), displayBadge: this.displayBadge(tag), badgeType: this.badgeType(tag), @@ -89,6 +89,21 @@ define( } }; + this.hashIdent = function(ident) { + if (typeof ident === 'undefined') { + return ''; + } + if (typeof ident === 'number') { + return ident; + } + if (ident.match(/^[a-zA-Z0-9 ]+$/)) { + return ident; + } + + /*jslint bitwise: true */ + return Math.abs(String(ident).split('').reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a;},0)); + }; + this.removeSearchingClass = function() { if (this.attr.tag.name === 'all'){ this.$node.removeClass('searching'); @@ -106,7 +121,7 @@ define( this.renderAndAttach = function (parent, data) { var rendered = this.viewFor(data.tag, templates.tags.tag); parent.append(rendered); - this.initialize('#tag-' + data.tag.ident, data); + this.initialize('#tag-' + this.hashIdent(data.tag.ident), data); this.on(parent, events.tags.teardown, this.teardown); }; } diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js index 55ca81c0..7e95f20a 100644 --- a/web-ui/test/spec/services/mail_service.spec.js +++ b/web-ui/test/spec/services/mail_service.spec.js @@ -201,7 +201,7 @@ describeComponent('services/mail_service', function () { this.component.trigger(Pixelated.events.ui.mails.fetchByTag, {tag: 'new tag'}); - expect($.ajax.calls.mostRecent().args[0]).toContain(encodeURI('tag:"new tag"')); + expect($.ajax.calls.mostRecent().args[0]).toContain(encodeURIComponent('tag:"new tag"')); }); it('sends the previous tag when mails:refresh is called without a tag (this happens when the refresher calls it)', function () { |