-
Notifications
You must be signed in to change notification settings - Fork 2
fix(quality): reduce cognitive complexity and fix shell script issues #136
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,7 @@ usage() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -z "$1" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -z "$1" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,14 +56,16 @@ analyze_html() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if grep -qE 'http://' "$file"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WARNINGS+=("$file: Contains non-HTTPS URLs") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Process files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -d "$TARGET" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| find "$TARGET" -name "*.html" -o -name "*.htm" | while read -r file; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -d "$TARGET" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while IFS= read -r -d '' file; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| analyze_html "$file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [ -f "$TARGET" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done < <(find "$TARGET" \( -name "*.html" -o -name "*.htm" \) -print0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [[ -f "$TARGET" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| analyze_html "$TARGET" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Error: $TARGET is not a valid file or directory" >&2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -74,14 +76,14 @@ fi | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '{' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo ' "issues": [' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in "${!ISSUES[@]}"; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ $i -gt 0 ]; then echo ','; fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ $i -gt 0 ]]; then echo ','; fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo -n " \"${ISSUES[$i]}\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo ' ],' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo ' "warnings": [' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in "${!WARNINGS[@]}"; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ $i -gt 0 ]; then echo ','; fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ $i -gt 0 ]]; then echo ','; fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo -n " \"${WARNINGS[$i]}\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+79
to
87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Escape JSON string values before emitting output. At Lines [80] and [87], raw strings are injected into JSON. Filenames containing quotes, backslashes, or newlines can produce invalid JSON. Suggested fix+json_escape() {
+ local s="$1"
+ s=${s//\\/\\\\}
+ s=${s//\"/\\\"}
+ s=${s//$'\n'/\\n}
+ s=${s//$'\r'/\\r}
+ s=${s//$'\t'/\\t}
+ printf '%s' "$s"
+}
+
# Output results as JSON
echo '{'
echo ' "issues": ['
for i in "${!ISSUES[@]}"; do
if [[ $i -gt 0 ]]; then echo ','; fi
- echo -n " \"${ISSUES[$i]}\""
+ printf ' "%s"' "$(json_escape "${ISSUES[$i]}")"
done
echo ''
echo ' ],'
echo ' "warnings": ['
for i in "${!WARNINGS[@]}"; do
if [[ $i -gt 0 ]]; then echo ','; fi
- echo -n " \"${WARNINGS[$i]}\""
+ printf ' "%s"' "$(json_escape "${WARNINGS[$i]}")"
done📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.