Skip to content

Commit

Permalink
Fix crash in case of unreachable symlinks
Browse files Browse the repository at this point in the history
Fixes #2525

Co-authored-by: Silvio Knizek <7925665+killermoehre@users.noreply.github.com>
  • Loading branch information
nvuillam and killermoehre committed Apr 8, 2023
1 parent 00df56b commit 0cb2ab1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
[#2455](https://github.com/oxsecurity/megalinter/pull/2455).

- Core
- Upgrade base Docker image to python:3.11.3-alpine3.17
- Fix issue preventing plugins to work with flavors
- Upgrade create-pull-request and create-or-update-comment GitHub Actions
- Increase auto-update-linters GitHub Action timeout
- Upgrade base Docker image to python:3.11.3-alpine3.17
- Fix crash in case of unreachable symlinks

- Documentation

Expand Down
12 changes: 8 additions & 4 deletions megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,14 @@ def check_activation_rules(activation_rules, _linter):
def file_contains(file_name: str, regex_object: Optional[Pattern[str]]) -> bool:
if not regex_object:
return True
with open(file_name, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
found_pattern = regex_object.search(content) is not None
return found_pattern
try:
with open(file_name, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
found_pattern = regex_object.search(content) is not None
return found_pattern
except Exception as e:
logging.warning(f"Unable to check content of file {file_name}: " + str(e))
return False


def file_is_generated(file_name: str) -> bool:
Expand Down

0 comments on commit 0cb2ab1

Please sign in to comment.