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 crash in case of unreachable symlinks #2538

Merged
merged 2 commits into from
Apr 10, 2023
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: 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