From a489d00aede8bdc1fbeeea57ce6744ce8f966fa2 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 27 Nov 2019 19:19:55 -0500 Subject: [PATCH] recognize domain characters correctly --- lib/philomena/images/image.ex | 2 +- lib/textile/lexer.ex | 1 + lib/textile/url_lexer.ex | 12 ++++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/philomena/images/image.ex b/lib/philomena/images/image.ex index 4c5a4a55..48cdf802 100644 --- a/lib/philomena/images/image.ex +++ b/lib/philomena/images/image.ex @@ -140,7 +140,7 @@ defmodule Philomena.Images.Image do |> validate_number(:image_height, greater_than: 0, less_than_or_equal_to: 32767) |> 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)) - |> unsafe_validate_unique([:image_sha512_hash], Repo) + |> unsafe_validate_unique([:image_orig_sha512_hash], Repo) end def source_changeset(image, attrs) do diff --git a/lib/textile/lexer.ex b/lib/textile/lexer.ex index fc43d33b..e82d539e 100644 --- a/lib/textile/lexer.ex +++ b/lib/textile/lexer.ex @@ -133,6 +133,7 @@ defmodule Textile.Lexer do string(","), string("_") |> concat(choice([space(), eos()])), string("?") |> concat(choice([space(), eos()])), + string(";") |> concat(choice([space(), eos()])), space(), eos() ]) diff --git a/lib/textile/url_lexer.ex b/lib/textile/url_lexer.ex index c99e7544..dcd5ef3f 100644 --- a/lib/textile/url_lexer.ex +++ b/lib/textile/url_lexer.ex @@ -2,11 +2,19 @@ defmodule Textile.UrlLexer do import NimbleParsec def url_ending_in(ending_sequence) do + domain_character = + choice([ + ascii_char([?a..?z]), + ascii_char([?A..?Z]), + ascii_char([?0..?9]), + string("-") + ]) + domain = repeat( choice([ - ascii_char([?a..?z]) |> string(".") |> ascii_char([?a..?z]), - ascii_char([?a..?z]) + domain_character |> string(".") |> concat(domain_character), + domain_character ]) )