recognize domain characters correctly

This commit is contained in:
byte[] 2019-11-27 19:19:55 -05:00
parent 9e5d4e02d8
commit a489d00aed
3 changed files with 12 additions and 3 deletions

View file

@ -140,7 +140,7 @@ defmodule Philomena.Images.Image do
|> validate_number(:image_height, greater_than: 0, less_than_or_equal_to: 32767) |> validate_number(:image_height, greater_than: 0, less_than_or_equal_to: 32767)
|> validate_length(:image_name, max: 255, count: :bytes) |> validate_length(:image_name, max: 255, count: :bytes)
|> validate_inclusion(:image_mime_type, ~W(image/gif image/jpeg image/png image/svg+xml video/webm)) |> validate_inclusion(:image_mime_type, ~W(image/gif image/jpeg image/png image/svg+xml video/webm))
|> unsafe_validate_unique([:image_sha512_hash], Repo) |> unsafe_validate_unique([:image_orig_sha512_hash], Repo)
end end
def source_changeset(image, attrs) do def source_changeset(image, attrs) do

View file

@ -133,6 +133,7 @@ defmodule Textile.Lexer do
string(","), string(","),
string("_") |> concat(choice([space(), eos()])), string("_") |> concat(choice([space(), eos()])),
string("?") |> concat(choice([space(), eos()])), string("?") |> concat(choice([space(), eos()])),
string(";") |> concat(choice([space(), eos()])),
space(), space(),
eos() eos()
]) ])

View file

@ -2,11 +2,19 @@ defmodule Textile.UrlLexer do
import NimbleParsec import NimbleParsec
def url_ending_in(ending_sequence) do def url_ending_in(ending_sequence) do
domain_character =
choice([
ascii_char([?a..?z]),
ascii_char([?A..?Z]),
ascii_char([?0..?9]),
string("-")
])
domain = domain =
repeat( repeat(
choice([ choice([
ascii_char([?a..?z]) |> string(".") |> ascii_char([?a..?z]), domain_character |> string(".") |> concat(domain_character),
ascii_char([?a..?z]) domain_character
]) ])
) )