Fix UTF-16 character handling in regex patterns
This commit is contained in:
parent
dc2b070e05
commit
49a897d79b
2 changed files with 9 additions and 1 deletions
|
@ -370,11 +370,18 @@ defmodule RDF.Literal do
|
|||
end
|
||||
|
||||
defp xpath_regex_pattern(pattern, flags) do
|
||||
with {:ok, regex} <- Regex.compile(pattern, xpath_regex_flags(flags)) do
|
||||
with {:ok, regex} <-
|
||||
pattern
|
||||
|> convert_utf16_escaping()
|
||||
|> Regex.compile(xpath_regex_flags(flags)) do
|
||||
{:regex, regex}
|
||||
end
|
||||
end
|
||||
|
||||
defp convert_utf16_escaping(pattern) do
|
||||
String.replace(pattern, ~r/\\U(([0-9]|[A-F]|[a-f]){2})(([0-9]|[A-F]|[a-f]){6})/, "\\u{\\3}")
|
||||
end
|
||||
|
||||
defp xpath_regex_flags(flags) do
|
||||
String.replace(flags, "q", "") <> "u"
|
||||
end
|
||||
|
|
|
@ -252,6 +252,7 @@ defmodule RDF.LiteralTest do
|
|||
{~L"abracadabra", ~L"^bra", false},
|
||||
{@poem, ~L"Kaum.*krähen", false},
|
||||
{@poem, ~L"^Kaum.*gesehen,$", false},
|
||||
{~L"\u{01D4B8}", ~L"\\U0001D4B8", true},
|
||||
|
||||
{~L"abracadabra"en, ~L"bra", true},
|
||||
{"abracadabra", "bra", true},
|
||||
|
|
Loading…
Reference in a new issue