test: fix regex compare for OTP28
This was technically already incorrect before and pointed out as such in documentation, but in practice worked well until OTP28’s regex changes.
This commit is contained in:
parent
cbae0760d0
commit
86d62173ff
3 changed files with 43 additions and 26 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
* PostgreSQL 12+
|
||||
* Elixir 1.15+ (currently tested up to 1.19)
|
||||
* Erlang OTP 25+ (currently tested up to OTP27)
|
||||
* Erlang OTP 25+ (currently tested up to OTP28)
|
||||
* git
|
||||
* file / libmagic
|
||||
* gcc (clang might also work)
|
||||
|
|
|
|||
|
|
@ -258,24 +258,28 @@ defmodule Pleroma.ConfigDBTest do
|
|||
end
|
||||
|
||||
test "sigil" do
|
||||
assert ConfigDB.to_elixir_types("~r[comp[lL][aA][iI][nN]er]") == ~r/comp[lL][aA][iI][nN]er/
|
||||
assert ConfigDB.to_elixir_types("~r[comp[lL][aA][iI][nN]er]").source ==
|
||||
~r/comp[lL][aA][iI][nN]er/.source
|
||||
end
|
||||
|
||||
test "link sigil" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/") == ~r/https:\/\/example.com/
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/").source ==
|
||||
~r/https:\/\/example.com/.source
|
||||
end
|
||||
|
||||
test "link sigil with um modifiers" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/um") ==
|
||||
~r/https:\/\/example.com/um
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/um").source ==
|
||||
~r/https:\/\/example.com/um.source
|
||||
end
|
||||
|
||||
test "link sigil with i modifier" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/i") == ~r/https:\/\/example.com/i
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/i").source ==
|
||||
~r/https:\/\/example.com/i.source
|
||||
end
|
||||
|
||||
test "link sigil with s modifier" do
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/s") == ~r/https:\/\/example.com/s
|
||||
assert ConfigDB.to_elixir_types("~r/https:\/\/example.com/s").source ==
|
||||
~r/https:\/\/example.com/s.source
|
||||
end
|
||||
|
||||
test "raise if valid delimiter not found" do
|
||||
|
|
@ -441,15 +445,18 @@ defmodule Pleroma.ConfigDBTest do
|
|||
end
|
||||
|
||||
test "complex keyword with sigil" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":federated_timeline_removal", []]},
|
||||
%{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]},
|
||||
%{"tuple" => [":replace", []]}
|
||||
]) == [
|
||||
federated_timeline_removal: [],
|
||||
reject: [~r/comp[lL][aA][iI][nN]er/],
|
||||
replace: []
|
||||
]
|
||||
[
|
||||
federated_timeline_removal: [],
|
||||
reject: [reject_regex],
|
||||
replace: []
|
||||
] =
|
||||
ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":federated_timeline_removal", []]},
|
||||
%{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]},
|
||||
%{"tuple" => [":replace", []]}
|
||||
])
|
||||
|
||||
assert reject_regex.source == ~r/comp[lL][aA][iI][nN]er/.source
|
||||
end
|
||||
|
||||
test "complex keyword with tuples with more than 2 values" do
|
||||
|
|
|
|||
|
|
@ -7,18 +7,28 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
use Pleroma.Tests.Helpers
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
defp regexes_equal([], []), do: true
|
||||
|
||||
defp regexes_equal([areg | arest], [breg | brest]),
|
||||
do: areg.source == breg.source and regexes_equal(arest, brest)
|
||||
|
||||
defp regexes_equal(_a, _b), do: false
|
||||
|
||||
test "subdomains_regex/1" do
|
||||
assert MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]) == [
|
||||
~r/^(.+\.)?unsafe\.tld$/i,
|
||||
~r/^(.+\.)?unsafe\.tld$/i
|
||||
]
|
||||
assert regexes_equal(
|
||||
MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]),
|
||||
[
|
||||
~r/^(.+\.)?unsafe\.tld$/i,
|
||||
~r/^(.+\.)?unsafe\.tld$/i
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
describe "subdomain_match/2" do
|
||||
test "common domains" do
|
||||
regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?unsafe\.tld$/i, ~r/^(.+\.)?unsafe2\.tld$/i]
|
||||
assert regexes_equal(regexes, [~r/^(.+\.)?unsafe\.tld$/i, ~r/^(.+\.)?unsafe2\.tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "unsafe2.tld")
|
||||
|
|
@ -29,7 +39,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "wildcard domains with one subdomain" do
|
||||
regexes = MRF.subdomains_regex(["unsafe.tld"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?unsafe\.tld$/i]
|
||||
assert regexes_equal(regexes, [~r/^(.+\.)?unsafe\.tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
|
||||
|
|
@ -40,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "wildcard domains with two subdomains" do
|
||||
regexes = MRF.subdomains_regex(["unsafe.tld"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?unsafe\.tld$/i]
|
||||
assert regexes_equal(regexes, [~r/^(.+\.)?unsafe\.tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
|
||||
|
|
@ -51,7 +61,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "wildcard on the tld" do
|
||||
regexes = MRF.subdomains_regex(["somewhere.*"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?somewhere\.(.+)$/i]
|
||||
assert regexes_equal(regexes, [~r/^(.+\.)?somewhere\.(.+)$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.net")
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.com")
|
||||
|
|
@ -62,7 +72,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "wildcards on subdomain _and_ tld" do
|
||||
regexes = MRF.subdomains_regex(["*.somewhere.*"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?somewhere\.(.+)$/i]
|
||||
assert regexes_equal(regexes, [~r/^(.+\.)?somewhere\.(.+)$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.net")
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.com")
|
||||
|
|
@ -76,7 +86,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "matches are case-insensitive" do
|
||||
regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?UnSafe\.TLD$/i, ~r/^(.+\.)?UnSAFE2\.Tld$/i]
|
||||
assert regexes_equal(regexes, [~r/^(.+\.)?UnSafe\.TLD$/i, ~r/^(.+\.)?UnSAFE2\.Tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
|
||||
assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue