diff --git a/src/HotChocolate/Core/src/Types.Scalars/EmailAddressType.cs b/src/HotChocolate/Core/src/Types.Scalars/EmailAddressType.cs index abb156eae93..bab5f735ec2 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/EmailAddressType.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/EmailAddressType.cs @@ -13,8 +13,8 @@ namespace HotChocolate.Types; public partial class EmailAddressType : RegexType { private const string ValidationPattern = - "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?" - + "(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"; + @"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?" + + @"(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z"; [GeneratedRegex(ValidationPattern, RegexOptions.None, DefaultRegexTimeoutInMs)] private static partial Regex CreateRegex(); diff --git a/src/HotChocolate/Core/src/Types.Scalars/HexColorType.cs b/src/HotChocolate/Core/src/Types.Scalars/HexColorType.cs index 4664a860c10..d5c107ff703 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/HexColorType.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/HexColorType.cs @@ -10,7 +10,7 @@ namespace HotChocolate.Types; public partial class HexColorType : RegexType { private const string ValidationPattern = - "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$"; + @"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})\z"; [GeneratedRegex(ValidationPattern, RegexOptions.None, DefaultRegexTimeoutInMs)] private static partial Regex CreateRegex(); diff --git a/src/HotChocolate/Core/src/Types.Scalars/IPv4Type.cs b/src/HotChocolate/Core/src/Types.Scalars/IPv4Type.cs index c63b5d53454..4550cb7f445 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/IPv4Type.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/IPv4Type.cs @@ -10,9 +10,9 @@ namespace HotChocolate.Types; public partial class IPv4Type : RegexType { private const string ValidationPattern = - "(^(?:(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}(?:0?0?" - + "[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\/(?:[0-9]|[1-2][0-9]|3[0" - + "-2]))?)$)"; + @"(^(?:(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?" + + @"[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\/(?:[0-9]|[1-2][0-9]|3[0" + + @"-2]))?)\z)"; [GeneratedRegex(ValidationPattern, RegexOptions.None, DefaultRegexTimeoutInMs)] private static partial Regex CreateRegex(); diff --git a/src/HotChocolate/Core/src/Types.Scalars/IPv6Type.cs b/src/HotChocolate/Core/src/Types.Scalars/IPv6Type.cs index 34631d343d2..9db05f0bbb1 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/IPv6Type.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/IPv6Type.cs @@ -31,7 +31,7 @@ public partial class IPv6Type : RegexType + "1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[" + "0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f" + "]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)(?:\\/(?:0?0?[0-9]|0?[" - + "1-9][0-9]|1[01][0-9]|12[0-8]))?)$)"; + + "1-9][0-9]|1[01][0-9]|12[0-8]))?)\\z)"; [GeneratedRegex(ValidationPattern, RegexOptions.None, DefaultRegexTimeoutInMs)] private static partial Regex CreateRegex(); diff --git a/src/HotChocolate/Core/src/Types.Scalars/IsbnType.cs b/src/HotChocolate/Core/src/Types.Scalars/IsbnType.cs index bcb53e42100..716399efa13 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/IsbnType.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/IsbnType.cs @@ -10,12 +10,12 @@ namespace HotChocolate.Types; public partial class IsbnType : RegexType { private const string ValidationPattern = - "^(?:ISBN(-1(?:(0)|3))?:?\\ )?(?(1)(?(2)(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0" - + "-9X]{13}$)[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]|(?=[0-9]{13}$|(?=(?:[0-9]" - + "+[- ]){4})[- 0-9]{17}$)97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9])|(" - + "?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$|97[89][0-9]{10}$|(?=(?:[0-9]+[" - + "- ]){4})[- 0-9]{17}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X" - + "])$"; + @"^(?:ISBN(-1(?:(0)|3))?:?\ )?(?(1)(?(2)(?=[0-9X]{10}\z|(?=(?:[0-9]+[- ]){3})[- 0" + + @"-9X]{13}\z)[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]|(?=[0-9]{13}\z|(?=(?:[0-9]" + + @"+[- ]){4})[- 0-9]{17}\z)97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9])|(" + + @"?=[0-9X]{10}\z|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}\z|97[89][0-9]{10}\z|(?=(?:[0-9]+[" + + @"- ]){4})[- 0-9]{17}\z)(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X" + + @"])\z"; [GeneratedRegex(ValidationPattern, RegexOptions.IgnoreCase, DefaultRegexTimeoutInMs)] private static partial Regex CreateRegex(); diff --git a/src/HotChocolate/Core/src/Types.Scalars/LatitudeType.cs b/src/HotChocolate/Core/src/Types.Scalars/LatitudeType.cs index b39be587da4..e20b5111fd4 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/LatitudeType.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/LatitudeType.cs @@ -89,8 +89,8 @@ private static class Latitude private const int MaxPrecision = 8; private const string SexagesimalRegex = - "^([0-9]{1,3})°\\s*([0-9]{1,3}(?:\\.(?:[0-9]{1,}))?)['′]\\s*(([0-9]{1,3}" - + "(\\.([0-9]{1,}))?)[\"″]\\s*)?([NEOSW]?)$"; + @"^([0-9]{1,3})°\s*([0-9]{1,3}(?:\.(?:[0-9]{1,}))?)['′]\s*(([0-9]{1,3}" + + @"(\.([0-9]{1,}))?)[""″]\s*)?([NEOSW]?)\z"; private static readonly Regex s_validationPattern = new(SexagesimalRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase); diff --git a/src/HotChocolate/Core/src/Types.Scalars/LongitudeType.cs b/src/HotChocolate/Core/src/Types.Scalars/LongitudeType.cs index 4300d313143..fdf4ca08d26 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/LongitudeType.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/LongitudeType.cs @@ -89,8 +89,8 @@ private static class Longitude private const int MaxPrecision = 8; private const string SexagesimalRegex = - "^([0-9]{1,3})°\\s*([0-9]{1,3}(?:\\.(?:[0-9]{1,}))?)['′]\\s*(([0-9]{1,3}" - + "(\\.([0-9]{1,}))?)[\"″]\\s*)?([NEOSW]?)$"; + @"^([0-9]{1,3})°\s*([0-9]{1,3}(?:\.(?:[0-9]{1,}))?)['′]\s*(([0-9]{1,3}" + + @"(\.([0-9]{1,}))?)[""″]\s*)?([NEOSW]?)\z"; private static readonly Regex s_validationPattern = new(SexagesimalRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase); diff --git a/src/HotChocolate/Core/src/Types.Scalars/MacAddressType.cs b/src/HotChocolate/Core/src/Types.Scalars/MacAddressType.cs index db17df9f2df..e5398dc7285 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/MacAddressType.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/MacAddressType.cs @@ -18,7 +18,7 @@ public class MacAddressType : RegexType { private const string ValidationPattern = @"^(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})(?:(?:\1|\.)(?:[0-9A-Fa-f]{2}([:-]?)" - + "[0-9A-Fa-f]{2})){2,3}$"; + + @"[0-9A-Fa-f]{2})){2,3}\z"; #if BACKREFERENCE_NOT_SUPPORTED [GeneratedRegex(_validationPattern, RegexOptions.None, DefaultRegexTimeoutInMs)] diff --git a/src/HotChocolate/Core/src/Types.Scalars/PhoneNumberType.cs b/src/HotChocolate/Core/src/Types.Scalars/PhoneNumberType.cs index 46be63fb646..2ea9b2153ff 100644 --- a/src/HotChocolate/Core/src/Types.Scalars/PhoneNumberType.cs +++ b/src/HotChocolate/Core/src/Types.Scalars/PhoneNumberType.cs @@ -12,7 +12,7 @@ public partial class PhoneNumberType : RegexType /// /// Regex that validates the standard E.164 format /// - private const string ValidationPattern = "^\\+[1-9][0-9]{2,14}$"; + private const string ValidationPattern = @"^\+[1-9][0-9]{2,14}\z"; [GeneratedRegex(ValidationPattern, RegexOptions.None, DefaultRegexTimeoutInMs)] private static partial Regex CreateRegex(); diff --git a/src/HotChocolate/Core/test/Types.Scalars.Tests/RegexTypeTests.cs b/src/HotChocolate/Core/test/Types.Scalars.Tests/RegexTypeTests.cs index e91cee94636..4316fcb339b 100644 --- a/src/HotChocolate/Core/test/Types.Scalars.Tests/RegexTypeTests.cs +++ b/src/HotChocolate/Core/test/Types.Scalars.Tests/RegexTypeTests.cs @@ -123,7 +123,7 @@ public class StubType : RegexType /// /// Regex that validates the standard E.164 format /// - private const string ValidationPattern = "^\\+[1-9][0-9]{2,14}$"; + private const string ValidationPattern = @"^\+[1-9][0-9]{2,14}\z"; /// /// Initializes a new instance of the