Bug 24968

Summary: All characters are allowed as Unicode escape sequences within identifiers
Product: [Mono] Compilers Reporter: Jon Skeet <skeet>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: marcin.kolny, mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Tags: Is this bug a regression?: ---
Last known good build:

Description Jon Skeet 2014-12-01 17:28:15 UTC
Description of Problem: The spec allows Unicode escape sequences within identifiers, but only if the escaped character is a valid character within the identifier. mcs allows *any* character


Steps to reproduce the problem:
1. Compile this line of code within a method:

    string x\u0020y = "";

Actual Results: It compiles, declaring a variable with identifier xy


Expected Results: Compile-time error.


How often does this happen? Always.


Additional Information:

Validated against version 3.3.0.0 (not listed in the version list above!) and against head.

Piece of code in error:
https://github.com/mono/mono/blob/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/mcs/cs-tokenizer.cs#L3068

(If the escaped character isn't a valid identifier, it should put it back and break out of the loop.)
Comment 1 Marcin Kolny 2015-02-25 16:22:07 UTC
Right. According to documentation: https://msdn.microsoft.com/en-us/library/aa664670.aspx in the identifier can be used any unicode character from following character classes: Lu, Ll, Lt, Lm, Lo, Nl, Mn, Mc, Nd, Pc, and Cf (except first letter, which should be one of the character from classes: Lu, Ll, Lt, Lm, Lo or underscore).
I'm working on pull request now.
Comment 2 Marcin Kolny 2015-02-25 16:34:22 UTC
I also noted, that there is also problem with first character in the identifier. It will be fixed in my patch too.
Comment 3 Marcin Kolny 2015-02-25 17:40:29 UTC
Now I see that Nl is also letter-character, but IsLetter doesn't treat this characters as letter-character, so it should be explicitly checked in is_identifier_start_character method.
Comment 4 Marcin Kolny 2015-02-25 19:13:16 UTC
My pull request which solves problem: https://github.com/mono/mono/pull/1601
Comment 5 Marek Safar 2015-05-18 08:05:18 UTC
Fixed in master