Repository: microsoft/regorus (language: python)

Issue:
Handle # character within string correctly
Currently, Regorus treats the # character
- as a regular character within raw strings
- as a comment character within regular strings

This behavior is incorrect and does not match OPA which treats the # character as a regular character within both types of strings.


Discussion / hints:

Fix patch:
diff --git a/src/lexer.rs b/src/lexer.rs
index f4ae34c7..a7b02c53 100644
--- a/src/lexer.rs
+++ b/src/lexer.rs
@@ -455,7 +455,7 @@ impl<'source> Lexer<'source> {
             let (offset, ch) = self.peek();
             let col = self.col + (offset - start) as u16;
             match ch {
-                '"' | '#' | '\x00' => {
+                '"' | '\x00' => {
                     break;
                 }
                 '\\' => {


Test patch:
diff --git a/tests/lexer/cases/comment.yaml b/tests/lexer/cases/comment.yaml
index 0ec359dc..4a4259ea 100644
--- a/tests/lexer/cases/comment.yaml
+++ b/tests/lexer/cases/comment.yaml
@@ -56,11 +56,9 @@ cases:
 
   - note: comments-within-rstring
     rego: |
-      #Comments aren't allowed within strings,
-      "#This is not a comment
-      "#c
-    tokens:
-    error: unmatched "
+      #Comments aren't lexed within raw strings.
+      "#This is not a comment"#c
+    tokens: ["#This is not a comment", ""]
 
   - note: comment-integer-break
     rego: |