File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
ruby/ql/src/queries/security/cwe-020 Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change 6
6
<overview >
7
7
<p >
8
8
Regular expressions in Ruby can use anchors to match the beginning and end of a string.
9
- However, if the <code >^</code > and <code >$</code > anchors are not used,
9
+ However, if the <code >^</code > and <code >$</code > anchors are used,
10
10
the regular expression can match a single line of a multi-line string.
11
11
</p >
12
12
</overview >
26
26
27
27
<sample language =" ruby" >
28
28
def bad(input)
29
- raise "Bad input" unless input =~ /[0-9]+/
29
+ raise "Bad input" unless input =~ /^ [0-9]+$ /
30
30
31
31
# ....
32
32
end
33
33
</sample >
34
34
35
35
<p >
36
- The regular expression <code >[0-9]+</code > will match a single line of a multi-line string,
36
+ The regular expression <code >/^ [0-9]+$/ </code > will match a single line of a multi-line string,
37
37
which may not be the intended behavior.
38
38
To match the entire string, the regular expression should be <code >\A[0-9]+\z</code >.
39
39
</p >
You can’t perform that action at this time.
0 commit comments