Commit 4f1a91be authored by Aron Carroll's avatar Aron Carroll

Add a new urlencode filter

This escapes any special url characters in the term
parent d76e9f82
...@@ -25,7 +25,8 @@ momentFilter = -> ...@@ -25,7 +25,8 @@ momentFilter = ->
momentDate.format('LLLL') momentDate.format('LLLL')
persona = (user, part='username') -> personaFilter = ->
(user, part='username') ->
index = ['term', 'username', 'provider'].indexOf(part) index = ['term', 'username', 'provider'].indexOf(part)
groups = user?.match /^acct:([^@]+)@(.+)/ groups = user?.match /^acct:([^@]+)@(.+)/
if groups if groups
...@@ -33,8 +34,12 @@ persona = (user, part='username') -> ...@@ -33,8 +34,12 @@ persona = (user, part='username') ->
else if part != 'provider' else if part != 'provider'
user user
urlEncodeFilter = ->
(value) -> encodeURIComponent(value)
angular.module('h') angular.module('h')
.filter('converter', -> (new Converter()).makeHtml) .filter('converter', -> (new Converter()).makeHtml)
.filter('moment', momentFilter) .filter('moment', momentFilter)
.filter('persona', -> persona) .filter('persona', personaFilter)
.filter('urlencode', urlEncodeFilter)
...@@ -10,7 +10,8 @@ describe 'persona', -> ...@@ -10,7 +10,8 @@ describe 'persona', ->
filter = $filter('persona') filter = $filter('persona')
it 'should return the whole term by request', -> it 'should return the whole term by request', ->
assert.equal filter('acct:hacker@example.com', 'term'), 'acct:hacker@example.com' result = filter('acct:hacker@example.com', 'term')
assert.equal result, 'acct:hacker@example.com'
it 'should return the requested part', -> it 'should return the requested part', ->
assert.equal filter(term), 'hacker' assert.equal filter(term), 'hacker'
...@@ -25,3 +26,13 @@ describe 'persona', -> ...@@ -25,3 +26,13 @@ describe 'persona', ->
it 'should handle error cases', -> it 'should handle error cases', ->
assert.notOk filter() assert.notOk filter()
assert.notOk filter('bogus', 'provider') assert.notOk filter('bogus', 'provider')
describe 'urlencode', ->
filter = null
beforeEach module('h')
beforeEach inject ($filter) ->
filter = $filter('urlencode')
it 'encodes reserved characters in the term', ->
assert.equal(filter('#hello world'), '%23hello%20world')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment