Skip to content

Commit 0874712

Browse files
committed
C++/Java/Python: Allow Python string prefix in InlineExpectationsTest
I've been writing tests for crypto libraries in Python, and have wanted to write code along the lines of ```py md5.hash(b"some message") # $ HashInput=b"some message" ``` which didn't work before this commit, forcing me to store my text in a variable like below. This turned out to be really annoying when dealing with more complex examples, so therefore I'm adding this new functionality to allow this behavior. ```py msg = b"some message" md5.hash(msg) # $ HashInput=msg ```
1 parent 37baf77 commit 0874712

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

cpp/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ private string expectationPattern() {
233233
exists(string tag, string tags, string value |
234234
tag = "[A-Za-z-_][A-Za-z-_0-9]*" and
235235
tags = "((?:" + tag + ")(?:\\s*,\\s*" + tag + ")*)" and
236-
value = "((?:\"[^\"]*\"|'[^']*'|\\S+)*)" and
236+
// In Python, we allow both `"` and `'` for strings, as well as the prefixes `bru`.
237+
// For example, `b"foo"`.
238+
value = "((?:[bru]*\"[^\"]*\"|[bru]*'[^']*'|\\S+)*)" and
237239
result = tags + "(?:=" + value + ")?"
238240
)
239241
}

java/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ private string expectationPattern() {
233233
exists(string tag, string tags, string value |
234234
tag = "[A-Za-z-_][A-Za-z-_0-9]*" and
235235
tags = "((?:" + tag + ")(?:\\s*,\\s*" + tag + ")*)" and
236-
value = "((?:\"[^\"]*\"|'[^']*'|\\S+)*)" and
236+
// In Python, we allow both `"` and `'` for strings, as well as the prefixes `bru`.
237+
// For example, `b"foo"`.
238+
value = "((?:[bru]*\"[^\"]*\"|[bru]*'[^']*'|\\S+)*)" and
237239
result = tags + "(?:=" + value + ")?"
238240
)
239241
}

python/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ private string expectationPattern() {
233233
exists(string tag, string tags, string value |
234234
tag = "[A-Za-z-_][A-Za-z-_0-9]*" and
235235
tags = "((?:" + tag + ")(?:\\s*,\\s*" + tag + ")*)" and
236-
value = "((?:\"[^\"]*\"|'[^']*'|\\S+)*)" and
236+
// In Python, we allow both `"` and `'` for strings, as well as the prefixes `bru`.
237+
// For example, `b"foo"`.
238+
value = "((?:[bru]*\"[^\"]*\"|[bru]*'[^']*'|\\S+)*)" and
237239
result = tags + "(?:=" + value + ")?"
238240
)
239241
}

0 commit comments

Comments
 (0)