Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
4f1a91be
Commit
4f1a91be
authored
Jan 26, 2015
by
Aron Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a new urlencode filter
This escapes any special url characters in the term
parent
d76e9f82
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
9 deletions
+25
-9
filters.coffee
h/static/scripts/filters.coffee
+13
-8
filters-test.coffee
tests/js/filters-test.coffee
+12
-1
No files found.
h/static/scripts/filters.coffee
View file @
4f1a91be
...
@@ -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
)
tests/js/filters-test.coffee
View file @
4f1a91be
...
@@ -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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment