Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
392
Issues
392
List
Boards
Labels
Service Desk
Milestones
Merge Requests
54
Merge Requests
54
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pleroma
pleroma
Commits
a237c6a2
Commit
a237c6a2
authored
Jul 10, 2019
by
Alexander Strizhakov
Committed by
kaniini
Jul 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for idna domains
parent
3ff4a06e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
3 deletions
+133
-3
lib/pleroma/user/search.ex
lib/pleroma/user/search.ex
+14
-3
test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml
test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml
+5
-0
test/fixtures/lain.xml
test/fixtures/lain.xml
+12
-0
test/support/http_request_mock.ex
test/support/http_request_mock.ex
+39
-0
test/user_search_test.exs
test/user_search_test.exs
+52
-0
test/web/web_finger/web_finger_test.exs
test/web/web_finger/web_finger_test.exs
+11
-0
No files found.
lib/pleroma/user/search.ex
View file @
a237c6a2
...
...
@@ -18,8 +18,7 @@ def search(query_string, opts \\ []) do
for_user = Keyword.get(opts, :for_user)
# Strip the beginning @ off if there is a query
query_string
=
String
.
trim_leading
(
query_string
,
"@"
)
query_string = format_query(query_string)
maybe_resolve(resolve, for_user, query_string)
...
...
@@ -40,6 +39,18 @@ def search(query_string, opts \\ []) do
results
end
defp format_query(query_string) do
# Strip the beginning @ off if there is a query
query_string = String.trim_leading(query_string, "@")
with [name, domain] <- String.split(query_string, "@"),
formatted_domain <- String.replace(domain, ~r/[!-\-|@|[-`|{-~|\/|:]+/, "") do
name <> "@" <> to_string(:idna.encode(formatted_domain))
else
_ -> query_string
end
end
defp search_query(query_string, for_user, following) do
for_user
|> base_query(following)
...
...
@@ -151,7 +162,7 @@ defp boost_search_rank_query(query, for_user) do
defp fts_search_subquery(query, term) do
processed_query =
String.trim_trailing(term, "@" <> local_domain())
|>
String
.
replace
(
~r/
\W
+/
,
" "
)
|> String.replace(~r/
[!-\/|@|[-`|{-~|:-?]
+/, " ")
|> String.trim()
|> String.split()
|> Enum.map(&(&1 <> ":*"))
...
...
test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml
0 → 100644
View file @
a237c6a2
<?xml version="1.0" encoding="UTF-8"?>
<XRD
xmlns=
"http://docs.oasis-open.org/ns/xri/xrd-1.0"
>
<Link
rel=
"lrdd"
template=
"https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource={uri}"
type=
"application/xrd+xml"
/>
</XRD>
test/fixtures/lain.xml
0 → 100644
View file @
a237c6a2
<?xml version="1.0" encoding="UTF-8"?>
<XRD
xmlns=
"http://docs.oasis-open.org/ns/xri/xrd-1.0"
>
<Subject>
acct:lain@zetsubou.xn--q9jyb4c
</Subject>
<Alias>
https://zetsubou.xn--q9jyb4c/users/lain
</Alias>
<Link
href=
"https://zetsubou.xn--q9jyb4c/users/lain/feed.atom"
rel=
"http://schemas.google.com/g/2010#updates-from"
type=
"application/atom+xml"
/>
<Link
href=
"https://zetsubou.xn--q9jyb4c/users/lain"
rel=
"http://webfinger.net/rel/profile-page"
type=
"text/html"
/>
<Link
href=
"https://zetsubou.xn--q9jyb4c/users/lain/salmon"
rel=
"salmon"
/>
<Link
href=
"data:application/magic-public-key,RSA.7yTJNuPH7wSsg6sMH4XLi-OL6JL8idyRMwNsWy2xzKWPJRWVK5hxG1kMGQ4qC_9ksqIaT7c7DIQFJYYbhRTnXYdac1UxaWivzl5l2HYPOOF1_-gbE6TCaI4ItTQo5eB4yyy3zozrIuv_GY8W0Ww58Re8Z_G4DFFmnipgiBKNaHthxNQqtxcK-o4rUv3xdyr_M9KYi3QISCGiaV_t8xkdVREixzNmWpsqM5YZ46xXT0SiGSHDubLE_OGhyvWqf_WkJrnDBETL3WjXU4QsPmBbVBgLvLcHei_uAD-9d3QImSuWwBXXQZIzY7Diro6u8dZuPIoLmnbUp1-mViBwCUMWSQ==.AQAB"
rel=
"magic-public-key"
/>
<Link
href=
"https://zetsubou.xn--q9jyb4c/users/lain"
rel=
"self"
type=
"application/activity+json"
/>
<Link
rel=
"http://ostatus.org/schema/1.0/subscribe"
template=
"https://zetsubou.xn--q9jyb4c/ostatus_subscribe?acct={uri}"
/>
</XRD>
test/support/http_request_mock.ex
View file @
a237c6a2
...
...
@@ -840,6 +840,45 @@ def get("http://404.site" <> _, _, _, _) do
}}
end
def
get
(
"https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c"
,
_
,
_
,
Accept:
"application/xrd+xml,application/jrd+json"
)
do
{
:ok
,
%
Tesla
.
Env
{
status:
200
,
body:
File
.
read!
(
"test/fixtures/lain.xml"
)
}}
end
def
get
(
"https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain"
,
_
,
_
,
Accept:
"application/xrd+xml,application/jrd+json"
)
do
{
:ok
,
%
Tesla
.
Env
{
status:
200
,
body:
File
.
read!
(
"test/fixtures/lain.xml"
)
}}
end
def
get
(
"https://zetsubou.xn--q9jyb4c/.well-known/host-meta"
,
_
,
_
,
_
)
do
{
:ok
,
%
Tesla
.
Env
{
status:
200
,
body:
File
.
read!
(
"test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml"
)
}}
end
def
get
(
url
,
query
,
body
,
headers
)
do
{
:error
,
"Not implemented the mock response for get
#{
inspect
(
url
)
}
,
#{
query
}
,
#{
inspect
(
body
)
}
,
#{
...
...
test/user_search_test.exs
View file @
a237c6a2
...
...
@@ -248,5 +248,57 @@ test "local user search with users" do
[
result
]
=
User
.
search
(
"lain@localhost"
,
resolve:
true
,
for_user:
user
)
assert
Map
.
put
(
result
,
:search_rank
,
nil
)
|>
Map
.
put
(
:search_type
,
nil
)
==
local_user
end
test
"works with idna domains"
do
user
=
insert
(
:user
,
nickname:
"lain@"
<>
to_string
(
:idna
.
encode
(
"zetsubou.みんな"
)))
results
=
User
.
search
(
"lain@zetsubou.みんな"
,
resolve:
false
,
for_user:
user
)
result
=
List
.
first
(
results
)
assert
user
==
result
|>
Map
.
put
(
:search_rank
,
nil
)
|>
Map
.
put
(
:search_type
,
nil
)
end
test
"works with idna domains converted input"
do
user
=
insert
(
:user
,
nickname:
"lain@"
<>
to_string
(
:idna
.
encode
(
"zetsubou.みんな"
)))
results
=
User
.
search
(
"lain@zetsubou."
<>
to_string
(
:idna
.
encode
(
"zetsubou.みんな"
)),
resolve:
false
,
for_user:
user
)
result
=
List
.
first
(
results
)
assert
user
==
result
|>
Map
.
put
(
:search_rank
,
nil
)
|>
Map
.
put
(
:search_type
,
nil
)
end
test
"works with idna domains and bad chars in domain"
do
user
=
insert
(
:user
,
nickname:
"lain@"
<>
to_string
(
:idna
.
encode
(
"zetsubou.みんな"
)))
results
=
User
.
search
(
"lain@zetsubou!@#$%^&*()+,-/:;<=>?[]'_{}|~`.みんな"
,
resolve:
false
,
for_user:
user
)
result
=
List
.
first
(
results
)
assert
user
==
result
|>
Map
.
put
(
:search_rank
,
nil
)
|>
Map
.
put
(
:search_type
,
nil
)
end
test
"works with idna domains and query as link"
do
user
=
insert
(
:user
,
nickname:
"lain@"
<>
to_string
(
:idna
.
encode
(
"zetsubou.みんな"
)))
results
=
User
.
search
(
"https://zetsubou.みんな/users/lain"
,
resolve:
false
,
for_user:
user
)
result
=
List
.
first
(
results
)
assert
user
==
result
|>
Map
.
put
(
:search_rank
,
nil
)
|>
Map
.
put
(
:search_type
,
nil
)
end
end
end
test/web/web_finger/web_finger_test.exs
View file @
a237c6a2
...
...
@@ -104,5 +104,16 @@ test "it gets the xrd endpoint for statusnet" do
assert
template
==
"http://status.alpicola.com/main/xrd?uri={uri}"
end
test
"it works with idna domains as nickname"
do
nickname
=
"lain@"
<>
to_string
(
:idna
.
encode
(
"zetsubou.みんな"
))
{
:ok
,
_data
}
=
WebFinger
.
finger
(
nickname
)
end
test
"it works with idna domains as link"
do
ap_id
=
"https://"
<>
to_string
(
:idna
.
encode
(
"zetsubou.みんな"
))
<>
"/users/lain"
{
:ok
,
_data
}
=
WebFinger
.
finger
(
ap_id
)
end
end
end
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