From 906bfecc72c9579fb150ae33059b190a2a387225 Mon Sep 17 00:00:00 2001 From: "linear-code[bot]" <222613912+linear-code[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:57:21 +0000 Subject: [PATCH] fix(Engine): Standardise regex matching in the Elixir server-side SDK Anchor regex segment conditions at the start of the trait value, for every alternative, without requiring a full-string match. Generated with [Linear](https://linear.app/flagsmith/agent-session/58bae237-657f-42a7-a3f0-4a18638a498f) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com> --- lib/flagsmith_engine.ex | 2 +- test/unit/segment_conditions_test.exs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/flagsmith_engine.ex b/lib/flagsmith_engine.ex index 388103e..c8eac7b 100644 --- a/lib/flagsmith_engine.ex +++ b/lib/flagsmith_engine.ex @@ -510,7 +510,7 @@ defmodule Flagsmith.Engine do type: :string, value: t_value }) do - case Regex.compile(value) do + case Regex.compile(value, [:anchored]) do {:ok, regex} -> String.match?(t_value, regex) diff --git a/test/unit/segment_conditions_test.exs b/test/unit/segment_conditions_test.exs index ae49d27..27ef0fc 100644 --- a/test/unit/segment_conditions_test.exs +++ b/test/unit/segment_conditions_test.exs @@ -56,6 +56,13 @@ defmodule Flagsmith.Engine.SegmentConditionsTest do {:REGEX, "foo", "[a-z]+", true}, {:REGEX, "FOO", "[a-z]+", false}, {:REGEX, "1.2.3", "\\d", true}, + {:REGEX, "production", "prod", true}, + {:REGEX, "nonproduction", "prod", false}, + {:REGEX, "development", "prod|dev", true}, + {:REGEX, "nondevelopment", "prod|dev", false}, + {:REGEX, "jane@example.com", "@example\\.com$", false}, + {:REGEX, "jane@example.com", "^[^@]+@example\\.com$", true}, + {:REGEX, "foo", "[", false}, {:MODULO, 1, "2|0", false}, {:MODULO, 2, "2|0", true}, {:MODULO, 3, "2|0", false},