ESAPI / esapi-java-legacy

ESAPI (The OWASP Enterprise Security API) is a free, open source, web application security control library that makes it easier for programmers to write lower-risk applications.
https://owasp.org/www-project-enterprise-security-api/
Other
603 stars 364 forks source link

Whitespace check-in #720

Closed noloader closed 1 year ago

noloader commented 2 years ago

This commit removes extraneous trailing whitespace from text-based files.

The script used to clean the files is shown below. It is also available as a ZIP in case you want to add it to the distribution files: whitespace.sh.zip.

#!/usr/bin/env bash

if ! command -v unix2dos &>/dev/null; then
    echo "Please install unix2dos to fix end-of-line conversions"
    exit 1
fi

# Directory to process
ESAPI_DIR="${PWD}"

# sed options for Unix, Linux and MacOS
if [[ $(uname -s | grep -i 'darwin') ]] ; then
    SED_OPTS="-i ''"
else
    SED_OPTS="-i"
fi

# Clean trailing whitespace in java files
IFS= find "${ESAPI_DIR}" -type f -name '*.java' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"

done

# Clean trailing whitespace in text files
IFS= find "${ESAPI_DIR}" -type f -name '*.txt' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
    unix2dos "${file}" &>/dev/null

done

# Clean trailing whitespace in markdown files
IFS= find "${ESAPI_DIR}" -type f -name '*.md' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"

done

# Clean trailing whitespace in html files
IFS= find "${ESAPI_DIR}" -type f -name '*.html' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
    # unix2dos "${file}" &>/dev/null

done

exit 0
kwwall commented 2 years ago

@noloader - It's pretty much only the release notes and I think the CONTRIBUTING-TO-ESAPI.txt files that we leave in DOS format, because of all the Windows uses who still use 'notepad' (and not even 'notepad++') to read them. Sigh. But most of the other text files that I create are UNIX format.

Also, we don't have any files with whitespace in the name, so there's no need for the IFS= trick in the loops. What do you think we are? A bunch of cavemen? I'd personally reject any PR that had a file name with whitespace in the name.

kwwall commented 2 years ago

Also, trailing whitespace doesn't bother me that much. There are 'diff' options to ignore that. :)

noloader commented 2 years ago

Thanks @kwwall,

The problem I am running into is, files I touch have them. So when I clean up the files I touch it includes a bunch of changes not relevant to my work. My hope is to clear all the extraneous whitespace as a base line. Then, when I cleanup the files I touch there are no extra changes.

so there's no need for the IFS= trick in the loops

Yeah, the code I used was copy/paste from my Build Scripts. It handles whitespace in filenames properly, so it should never do any harm.

kwwall commented 2 years ago

I thought that @xeno6696 had addressed a bunch of the same files in PR

685, but apparently he only addressed tabs->spaces issue and not trailing

white space.

Also, I probably will accept your PR after the 2.5.0.0 release.

On Sat, Jul 16, 2022 at 6:59 PM Jeffrey Walton @.***> wrote:

Thanks @kwwall https://github.com/kwwall,

The problem I am running into is, files I touch have them. So when I clean up the files I touch it includes a bunch of changes not relevant to my work. My hope is to clear all the extraneous whitespace as a base line. Then, when I cleanup the files I touch there are no extra changes.

— Reply to this email directly, view it on GitHub https://github.com/ESAPI/esapi-java-legacy/pull/720#issuecomment-1186318755, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO6PG4DY2BYLOFCRRK6RPDVUM5E7ANCNFSM53YWM6TA . You are receiving this because you were mentioned.Message ID: @.***>

-- Blog: https://off-the-wall-security.blogspot.com/ | Twitter: @KevinWWall | OWASP ESAPI Project co-lead NSA: All your crypto bit are belong to us.

kwwall commented 1 year ago

dos2unix is what we would want for SOURCE files (if we we using this). We use UNIX convention, and expand tabs to 4 spaces. But if we really wanted to do this, there are less clunky ways to handle it such as Maven plugins or GitHub workflows.

Also, as per our CONTRIBUTING-TO-ESAP.txt file, we recommend contributors set their git property 'core.autocrlf' to 'input'.

-kevin

On Sat, Jul 16, 2022, 5:53 PM Jeffrey Walton @.***> wrote:

This commit removes extraneous trailing whitespace from text-based files.

The script used to clean the files is shown below. It is also available as a ZIP in case you want to add it to the distribution files: whitespace.sh.zip https://github.com/ESAPI/esapi-java-legacy/files/9126647/whitespace.sh.zip .

!/usr/bin/env bash

if ! command -v unix2dos &>/dev/null; then echo "Please install unix2dos to fix end-of-line conversions" exit 1fi

Directory to process

ESAPI_DIR="${PWD}"

sed options for Unix, Linux and MacOSif [[ $(uname -s | grep -i 'darwin') ]] ; then

SED_OPTS="-i ''"else
SED_OPTS="-i"fi

Clean trailing whitespace in java files

IFS= find "${ESAPI_DIR}" -type f -name '*.java' -print | while read -r filedo

sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
done

Clean trailing whitespace in text files

IFS= find "${ESAPI_DIR}" -type f -name '*.txt' -print | while read -r filedo

sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
unix2dos "${file}" &>/dev/null
done

Clean trailing whitespace in markdown files

IFS= find "${ESAPI_DIR}" -type f -name '*.md' -print | while read -r filedo

sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
done

Clean trailing whitespace in html files

IFS= find "${ESAPI_DIR}" -type f -name '*.html' -print | while read -r filedo

sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
# unix2dos "${file}" &>/dev/null
done

exit 0


You can view, comment on, or merge this pull request online at:

https://github.com/ESAPI/esapi-java-legacy/pull/720 Commit Summary

File Changes

(300 files https://github.com/ESAPI/esapi-java-legacy/pull/720/files)