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,16 +25,21 @@ momentFilter = -> ...@@ -25,16 +25,21 @@ momentFilter = ->
momentDate.format('LLLL') momentDate.format('LLLL')
persona = (user, part='username') -> personaFilter = ->
index = ['term', 'username', 'provider'].indexOf(part) (user, part='username') ->
groups = user?.match /^acct:([^@]+)@(.+)/ index = ['term', 'username', 'provider'].indexOf(part)
if groups groups = user?.match /^acct:([^@]+)@(.+)/
groups[index] if groups
else if part != 'provider' groups[index]
user else if part != 'provider'
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