From 6c56eb91efb4293bea185c524808c0a8b34d5d8b Mon Sep 17 00:00:00 2001 From: "Stephen M. Pallen" Date: Fri, 19 Jan 2018 19:22:07 -0500 Subject: [PATCH] fixed a number of phone number failures --- lib/auto_linker/parser.ex | 2 +- mix.exs | 2 +- test/parser_test.exs | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index dca53bc..23ec909 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -31,7 +31,7 @@ defmodule AutoLinker.Parser do @match_url ~r{^[\w\.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$} @match_scheme ~r{^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$} - @match_phone ~r"((?:\+|00)[17](?:[ \-\.])?|(?:\+|00)[1-9]\d{0,2}(?:[ \-\.])?|(?:\+|00)1[\-\.]\d{3}(?:[ \-\.])?)?(0\d|\([0-9]{3}\)|[1-9]{0,3})(?:((?:[ \-\.])[0-9]{2}){4}|((?:[0-9]{2}){4})|((?:[ \-\.])[0-9]{3}(?:[ \-\.])[0-9]{4})|([0-9]{7}))|(x[0-9][0-9]+)" + @match_phone ~r"((?:x\d{2,7})|(?:(?:\+?1\s?(?:[.-]\s?)?)?(?:\(\s?(?:[2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s?\)|(?:[2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s?(?:[.-]\s?)?)(?:[2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s?(?:[.-]\s?)?(?:[0-9]{4}))" @default_opts ~w(url)a diff --git a/mix.exs b/mix.exs index e7735eb..0255b74 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule AutoLinker.Mixfile do use Mix.Project - @version "0.2.0" + @version "0.2.1" def project do [ diff --git a/test/parser_test.exs b/test/parser_test.exs index 767a027..8749d82 100644 --- a/test/parser_test.exs +++ b/test/parser_test.exs @@ -35,7 +35,7 @@ defmodule AutoLinker.ParserTest do test "valid" do valid_phone_nunbers() |> Enum.each(fn number -> - assert number |> match_phone() |> is_list + assert number |> match_phone() |> valid_number?(number) end) end @@ -70,6 +70,12 @@ defmodule AutoLinker.ParserTest do end end + def valid_number?([list], number) do + assert List.last(list) == number + end + + def valid_number?(_, _), do: false + def valid_scheme_urls, do: [ "https://www.example.com", "http://www2.example.com", @@ -117,7 +123,15 @@ defmodule AutoLinker.ParserTest do "555.555.5555", "613-555-5555", "1 (555) 555-5555", - "(555) 555-5555" + "(555) 555-5555", + "1.555.555.5555", + "800 555-5555", + "1.800.555.5555", + "1 (800) 555-5555", + "888 555-5555", + "887 555-5555", + "1-877-555-5555", + "1 800 710-5515" ] def invalid_phone_numbers, do: [ @@ -127,3 +141,4 @@ defmodule AutoLinker.ParserTest do ] end +