Skip to content

Commit

Permalink
Include uuid in pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
rdk08 committed Oct 23, 2023
1 parent 72586ea commit 62cba87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/plausible/helpers/value.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
defmodule Plausible.ValueHelpers do
@prefix_pattern "[a-zA-Z]+"
@id_pattern "\\d+"
@uuid_pattern "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"

@spec validate(any(), keyword()) :: any()
def validate(value, type: :prefixed_id) when is_binary(value) do
prefixed_id_pattern = ~r/\A\w+-\d+\Z/
pattern = ~r/\A(#{@prefix_pattern})-(#{@id_pattern}|#{@uuid_pattern})\Z/

if Regex.match?(prefixed_id_pattern, value), do: value, else: nil
if Regex.match?(pattern, value), do: value, else: nil
end

def validate(nil, _), do: nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
company_id: 10,
job_id: 12,
page_id: 15,
product_id: "vendor-11",
product_id: "vendor-6a01cfb6-717a-11ee-b962-0242ac120002",
site_id: 9,
careers_application_form_uuid: "313a26c2-741c-421c-9a6b-f39c02c8d35c"
}
Expand All @@ -514,7 +514,7 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
event = get_event("special-props-test.com")

assert Map.get(event, :campaign_id) == "vendor-8"
assert Map.get(event, :product_id) == "vendor-11"
assert Map.get(event, :product_id) == "vendor-6a01cfb6-717a-11ee-b962-0242ac120002"
assert Map.get(event, :company_id) == 10
assert Map.get(event, :job_id) == 12
assert Map.get(event, :page_id) == 15
Expand Down

0 comments on commit 62cba87

Please sign in to comment.