Skip to content

Commit

Permalink
Added Text::Patterns::OCTAL_BYTE (issue #553).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 11, 2024
1 parent f3d6dd7 commit a7cde48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ronin/support/text/patterns/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ module Patterns
# @since 1.0.0
NUMBER = /[0-9]+/

# Regular expression for finding a octal bytes (0 - 377)
#
# @since 1.2.0
OCTAL_BYTE = /(?<=[^\d]|^)(?:3[0-7]{2}|[0-2][0-7]{2}|[0-7]{1,2})(?=[^\d]|$)/

# Regular expression for finding a decimal bytes (0 - 255)
#
# @since 1.2.0
Expand Down
14 changes: 14 additions & 0 deletions spec/text/patterns/numeric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
end
end

describe "OCTAL_BYTE" do
subject { described_class::OCTAL_BYTE }

it "must match 0 - 377" do
numbers = (0..255).map { |byte| byte.to_s(8) }

expect(numbers).to all(match(subject))
end

it "must not match numbers greater than 377" do
expect('378').to_not match(subject)
end
end

describe "DECIMAL_BYTE" do
subject { described_class::DECIMAL_BYTE }

Expand Down

0 comments on commit a7cde48

Please sign in to comment.