Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: octal rule triggers on time format #303

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added
- Add Python 3.12 support ([#315](https://github.com/warpnet/salt-lint/pull/315)).

### Fixed
- Ignore false positive result in rule 210 ([#303](https://github.com/warpnet/salt-lint/pull/303)).

## [0.9.2] (2023-02-09)
### Fixed
- Ensure version identification adheres to [PEP440](https://peps.python.org/pep-0440/) ([!304](https://github.com/warpnet/salt-lint/issues/304))
Expand Down
9 changes: 8 additions & 1 deletion saltlint/rules/YamlHasOctalValueRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ class YamlHasOctalValueRule(Rule):

bracket_regex = re.compile(r"^[^:]+:\s{0,}0[0-9]{1,}\s{0,}((?={#)|(?=#)|(?=$))")

exclude_regex = re.compile(r"[ T]\d\d:\d\d(?:[: ]|$)")

def match(self, file, line):
return self.bracket_regex.search(line)
found = self.bracket_regex.search(line)
if found:
# Skip false positive result if the exclude_regex matches.
if self.exclude_regex.search(found.group(0)):
return None
return found
13 changes: 12 additions & 1 deletion tests/unit/TestYamlHasOctalValueRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,20 @@

# MAC addresses shouldn't be matched, for more information see:
# https://github.com/warpnet/salt-lint/issues/202
infoblox_remove_record:
infoblox_remove_record1:
infoblox_host_record.absent:
- mac: 4c:f2:d3:1b:2e:05

infoblox_remove_record2:
infoblox_host_record.absent:
- mac: 05:f2:d3:1b:2e:4c

# time values should not trigger this rule
some_calendar_entry:
file.managed:
- name: /tmp/my_unit_file
- contents: |
oncalendar=Sun 18:00
'''

BAD_NUMBER_STATE = '''
Expand Down
Loading