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