Bug 11033 - Regular expression validation differs between mono and .Net
Summary: Regular expression validation differs between mono and .Net
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web ()
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-03-11 06:11 UTC by Henning Moe
Modified: 2017-10-21 21:48 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Test Project (198.30 KB, application/zip)
2015-03-03 16:06 UTC, Jon Goldberger [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Henning Moe 2013-03-11 06:11:28 UTC
RegularExpressionAttribute differs between .NET and Mono

public class RegexValidation
	public void TestToLong()
		var attribute = new System.ComponentModel.DataAnnotations.RegularExpressionAttribute (@"\d{4}");
		Assert.IsFalse(attribute.IsValid ("12345"));

This test fails on a testrunner using Mono 3.06 but will pass using .NET.
Writing the expression as ^\d{4}$ will pass both in .NET and Mono.
Comment 2 Jon Goldberger [MSFT] 2015-03-03 16:04:02 UTC
I am also seeing a difference between .NET and mono running the following tests:

	public class RegexNameMismatchTest
		public void PassesInVisualStudioButFailsInXamarinStudio()
			Assert.IsTrue(Regex.IsMatch("é", @"\p{IsLatin-1Supplement}"));

		public void FailsInVisualStudioButPassesInXamarinStudio()
			Assert.IsTrue(Regex.IsMatch("é", @"\p{IsLatin1Supplement}"));

As indicated by the method names, the first fails in Xamarin Studio while the second fails with Visual Studio. (version information below).

## Steps to reproduce

1. Open attached test project in VS and XS
2. Run tests.

Expected result: Test results will be the same in VS (.NET) and in XS (Mono)

Actual result: Test results are not the same.

## Test fail message for first test in Xamarin Studio:

System.ArgumentException : parsing "\p{IsLatin-1Supplement}" - Unknown property 'IsLatin'.
>Parameter name: \p{IsLatin-1Supplement}
>Stack trace:
>  at System.Text.RegularExpressions.Syntax.Parser.ParseUnicodeCategory () [0x000a6] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/parser.cs:800 
>  at System.Text.RegularExpressions.Syntax.Parser.ParseSpecial (RegexOptions options) [0x0016d] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/parser.cs:830 
>  at System.Text.RegularExpressions.Syntax.Parser.ParseGroup (System.Text.RegularExpressions.Syntax.Group group, RegexOptions options, System.Text.RegularExpressions.Syntax.Assertion assertion) [0x00143] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/parser.cs:218 
>  at System.Text.RegularExpressions.Syntax.Parser.ParseRegularExpression (System.String pattern, RegexOptions options) [0x00031] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/parser.cs:140 
>  at System.Text.RegularExpressions.Regex.CreateMachineFactory (System.String pattern, RegexOptions options) [0x00006] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/Regex.cs:344 
>  at System.Text.RegularExpressions.Regex.InitNewRegex () [0x00000] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/Regex.cs:325 
>  at System.Text.RegularExpressions.Regex.Init () [0x00027] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/Regex.cs:314 
>  at System.Text.RegularExpressions.Regex..ctor (System.String pattern, RegexOptions options) [0x0002b] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/Regex.cs:215 
>  at System.Text.RegularExpressions.Regex.IsMatch (System.String input, System.String pattern, RegexOptions options) [0x00000] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/Regex.cs:121 
>  at System.Text.RegularExpressions.Regex.IsMatch (System.String input, System.String pattern) [0x00000] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Text.RegularExpressions/Regex.cs:116 
>  at TestRegEx.RegexNameMismatchTest.PassesInVisualStudioButFailsInXamarinStudio () [0x00000] in /Users/apple/Downloads/TestRegEx/TestRegEx/Test.cs:12 
>  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
>  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00054] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/corlib/System.Reflection/MonoMethod.cs:230 

## Test fail message for second test in Visual Studio:

Test Name:	FailsInVisualStudioButPassesInXamarinStudio
>Test FullName:	TestRegEx.RegexNameMismatchTest.FailsInVisualStudioButPassesInXamarinStudio
>Test Source:	c:\LongPath\TestRegEx\TestRegEx\Test.cs : line 18
>Test Outcome:	Failed
>Test Duration:	0:00:00.035
>Result Message:	System.ArgumentException : parsing "\p{IsLatin1Supplement}" - Unknown property 'IsLatin1Supplement'.
>Result StackTrace:	
>at System.Text.RegularExpressions.RegexCharClass.SetFromProperty(String capname, Boolean invert, String pattern)
>at System.Text.RegularExpressions.RegexCharClass.AddCategoryFromName(String categoryName, Boolean invert, Boolean caseInsensitive, String pattern)
>at System.Text.RegularExpressions.RegexParser.ScanBackslash()
>at System.Text.RegularExpressions.RegexParser.ScanRegex()
>at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
>at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, Boolean useCache)
>at System.Text.RegularExpressions.Regex.IsMatch(String input, String pattern)
>at TestRegEx.RegexNameMismatchTest.FailsInVisualStudioButPassesInXamarinStudio() in c:\LongPath\TestRegEx\TestRegEx\Test.cs:line 19

## XS version info:

=== Xamarin Studio ===

Version 5.7.2 (build 7)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
	Mono 3.12.0 ((detached/b8f5055)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000077

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 9905782
Build date: 2015-02-26 11:05:07-0500

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 507020007
Git revision: dcf3f486177d3e625349b51a8f3be807e3fa7712
Build date: 2015-02-24 09:14:27-05
Xamarin addins: ea7c65bb7876e4a876ab365208e94acdf8f330ef

=== Operating System ===

Mac OS X 10.10.2
Darwin Jons-iMac.local 14.1.0 Darwin Kernel Version 14.1.0
    Mon Dec 22 23:10:38 PST 2014
    root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64

## VS version info:

Microsoft Visual Studio Ultimate 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.53349

Installed Version: Ultimate

Architecture and Modeling Tools   06181-004-0451031-02209
Microsoft Architecture and Modeling Tools
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

LightSwitch for Visual Studio 2013   06181-004-0451031-02209
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06181-004-0451031-02209
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06181-004-0451031-02209
Microsoft Visual Basic 2013

Visual C# 2013   06181-004-0451031-02209
Microsoft Visual C# 2013

Visual C++ 2013   06181-004-0451031-02209
Microsoft Visual C++ 2013

Visual F# 2013   06181-004-0451031-02209
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06181-004-0451031-02209
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06181-004-0451031-02209
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone

Microsoft Azure HDInsight HQL Service   1.0.0000.0
Language service for Hive query

Microsoft Azure HDInsight Tools for Visual Studio   1.0.0000.0
An integrated development environment for HDInsight application development.

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

Microsoft Azure Tools   2.4
Microsoft Azure Tools for Microsoft Visual Studio 2013 - v2.4.20730.1601

Microsoft Azure Tools   2.5
Microsoft Azure Tools for Microsoft Visual Studio 2013 - v2.5.21104.1601

Multilingual App Toolkit   3.1.1250.0
Multilingual App Toolkit helps you localize your Windows Store app by providing file management, pseudo and machine translation, translation editor, and build integration. http://go.microsoft.com/fwlink?linkid=245767

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.31105
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41025.0
Microsoft SQL Server Data Tools

Windows Azure Tools   2.3
Windows Azure Tools for Microsoft Visual Studio 2013 - v2.3.20320.1602

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.9.344.0 (e23ab72)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS (862702c6b8aa14a373e25f83ac45918556af41a2)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 3 Jon Goldberger [MSFT] 2015-03-03 16:06:01 UTC
Created attachment 10137 [details]
Test Project

Test project for issue noted in above comment
Comment 5 Alexander Köplinger [MSFT] 2017-10-21 21:48:02 UTC
I tried the above test cases and they pass in Mono now (likely because we're using the implementations from referencesource now).