Skip to content

Commit 6426b60

Browse files
committed
[MERGE #5658 @rhuanjl] Add check for non-ascii fix:#4268
Merge pull request #5658 from rhuanjl:ascii This PR adds an additional test to CI to block non-ascii characters, the tests, tools and Build folders are excluded from the check. This is based on the eol check test but with a different grep command. Additionally I found some non-ascii at the start of JavascriptString.cpp so have removed it. @dilijev please can you take a look
2 parents 4d82238 + 05c28a9 commit 6426b60

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

jenkins/check_ascii.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#-------------------------------------------------------------------------------------------------------
2+
# Copyright (C) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
#-------------------------------------------------------------------------------------------------------
5+
6+
# Need to make sure that the reference to origin/master is available.
7+
# We know that HEAD is checked out so that the tests on that source can be run.
8+
9+
# configure the sh environment to run scripts from the bin dir in case that's missing
10+
ls &> /dev/null # checking for ls script on the path
11+
if [ $? -ne 0 ]; then
12+
PATH=/bin:/usr/bin:$PATH
13+
fi
14+
15+
ERRFILE=check_ascii.sh.err
16+
rm -f $ERRFILE
17+
git diff --name-only `git merge-base origin/master HEAD` HEAD | grep -v -E "test/.*|tools/.*|Build/.*|/*.md|/*.txt|/*.vcxproj" | xargs -I % ./jenkins/check_file_ascii.sh %
18+
19+
if [ -e $ERRFILE ]; then # if error file exists then there were errors
20+
>&2 echo "--------------" # leading >&2 means echo to stderr
21+
>&2 echo "--- ERRORS ---"
22+
cat $ERRFILE 1>&2 # send output to stderr so it can be redirected as error if desired
23+
exit 1 # tell the caller there was an error (so Jenkins will fail the CI task)
24+
else
25+
echo "--- NO PROBLEMS DETECTED ---"
26+
fi

jenkins/check_file_ascii.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#-------------------------------------------------------------------------------------------------------
2+
# Copyright (C) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
#-------------------------------------------------------------------------------------------------------
5+
6+
ERRFILE=check_ascii.sh.err
7+
ERRFILETEMP=$ERRFILE.0
8+
9+
# display a helpful message for someone reading the log
10+
echo "Check ascii > Checking $1"
11+
12+
if [ ! -e $1 ]; then # the file wasn't present; not necessarily an error
13+
echo "WARNING: file not found: $1"
14+
exit 0 # don't report an error but don't run the rest of this file
15+
fi
16+
17+
# grep for non-ascii - also exclude unprintable control characters at the end of the range
18+
# specifically include x09 (tab) as it is used in pal sources which are not excluded
19+
# from this check
20+
LC_CTYPE=C grep -nP '[^\x09-\x7E]' $1 > $ERRFILETEMP
21+
if [ $? -eq 0 ]; then # grep found matches ($?==0), so we found non-ascii in the file
22+
echo "ERROR: non-ascii characters were introduced in $1" >> $ERRFILE
23+
24+
# Display a hexdump sample of the lines with non-ascii characters in them
25+
# Don't pollute the log with every single matching line, first 10 lines should be enough.
26+
echo "Displaying first 10 lines of text where non-ascii characters were found:" >> $ERRFILE
27+
LC_CTYPE=C grep -nP '[^\x09-\x7E]' $1 | xxd -g 1 > $ERRFILETEMP
28+
head -n 10 $ERRFILETEMP >> $ERRFILE
29+
30+
# To help the user, display how many lines of text actually contained non-ascii characters.
31+
LINECOUNT=`python -c "file=open('$ERRFILETEMP', 'r'); print len(file.readlines())"`
32+
echo "Total lines containing non-ascii: $LINECOUNT" >> $ERRFILE
33+
echo "--------------" >> $ERRFILE # same length as '--- ERRORS ---'
34+
fi
35+
36+
rm -f $ERRFILETEMP

lib/Runtime/Library/JavascriptString.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-------------------------------------------------------------------------------------------------------
1+
//-------------------------------------------------------------------------------------------------------
22
// Copyright (C) Microsoft. All rights reserved.
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------

netci.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ if (!branch.endsWith('-ci')) {
339339
CreateStyleCheckTasks('./jenkins/check_copyright.sh', 'ubuntu_check_copyright', 'Copyright Check')
340340
CreateStyleCheckTasks('./jenkins/check_eol.sh', 'ubuntu_check_eol', 'EOL Check')
341341
CreateStyleCheckTasks('./jenkins/check_tabs.sh', 'ubuntu_check_tabs', 'Tab Check')
342+
CreateStyleCheckTasks('./jenkins/check_ascii.sh', 'ubuntu_check_ascii', 'ASCII Check')
342343

343344
// --------------
344345
// XPLAT BRANCHES

0 commit comments

Comments
 (0)