Skip to content

Commit aa0a508

Browse files
committed
[SPARK-52717][INFRA] Escape special characters when redacting the log files in release build
### What changes were proposed in this pull request? This PR proposes to escape special characters when redacting the log files ### Why are the changes needed? Currently it fails to redact when there are special characters. ### Does this PR introduce _any_ user-facing change? No, dev-only. ### How was this patch tested? Manually tested. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51405 from HyukjinKwon/escape-patterns. Authored-by: Hyukjin Kwon <gurwls223@apache.org> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
1 parent a46296e commit aa0a508

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,18 @@ jobs:
227227
cp "$file" "$file.bak"
228228
for pattern in "${PATTERNS[@]}"; do
229229
[ -n "$pattern" ] || continue # Skip empty patterns
230-
escaped_pattern=$(printf '%s\n' "$pattern" | sed 's/[\/&]/\\&/g')
231-
sed -i "s/${escaped_pattern}/***/g" "$file"
230+
231+
# Safely escape special characters for sed
232+
escaped_pattern=${pattern//\\/\\\\} # Escape backslashes
233+
escaped_pattern=${escaped_pattern//\//\\/} # Escape forward slashes
234+
escaped_pattern=${escaped_pattern//&/\\&} # Escape &
235+
escaped_pattern=${escaped_pattern//$'\n'/} # Remove newlines
236+
escaped_pattern=${escaped_pattern//$'\r'/} # Remove carriage returns (optional)
237+
238+
# Redact the pattern
239+
sed -i.bak "s/${escaped_pattern}/***/g" "$file"
232240
done
241+
rm -f "$file.bak"
233242
done
234243
235244
# Zip logs/output

0 commit comments

Comments
 (0)