Skip to content

Commit 1780d64

Browse files
committed
ci: add action to validate source strings, excluding escaped characters
1 parent bd7246f commit 1780d64

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Validate Android source strings
2+
3+
on:
4+
push:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
validate-strings:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v5
16+
17+
- name: Install xmlstarlet
18+
run: sudo apt-get update && sudo apt-get install -y xmlstarlet
19+
20+
- name: Validate source strings
21+
shell: bash
22+
run: |
23+
xml_file="owncloudApp/src/main/res/values/strings.xml"
24+
has_errors=0
25+
26+
# ANSI-C quoting to read characters correctly
27+
forbidden_values=($'\'' $'"' $'@' $'\n' $'\t')
28+
escaped_values=($'\\\'' $'\\"' $'\\@' $'\\n' $'\\t')
29+
30+
# Read one line every iteration
31+
while IFS= read -r line; do
32+
33+
# Takes everything on the left of ^^
34+
string_name="${line%%^^*}"
35+
# Takes everything on the right of ^^
36+
string_value="${line#*^^}"
37+
38+
# Check if the string contains any of the escaped_values and remove it
39+
for escaped in "${escaped_values[@]}"; do
40+
string_value="${string_value//"$escaped"/}"
41+
done
42+
43+
# Check if the string contains any of the forbidden_values
44+
for forbidden in "${forbidden_values[@]}"; do
45+
if [[ "$string_value" == *"$forbidden"* ]]; then
46+
echo "Source string \"$string_name\" contains forbidden characters"
47+
has_errors=1
48+
break
49+
fi
50+
done
51+
# Read the input file line by line
52+
done < <(
53+
xmlstarlet sel \
54+
-t \
55+
-m '/resources/string' \
56+
-v '@name' \
57+
-o '^^' \
58+
-v '.' \
59+
-n \
60+
"$xml_file"
61+
)
62+
63+
exit $has_errors

0 commit comments

Comments
 (0)