Skip to content

Commit

Permalink
Fix edge case in code audit when there is a - in the src path
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Nov 21, 2024
1 parent 33a6d5a commit b756d9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/include/audit_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ function _get_grep_context() {
# given a matches line from grep -B output
# it will return - or : depeding if its the
# context or actual match
[[ "$1" =~ [^a-zA-Z0-9/.] ]] && printf '%s' "${BASH_REMATCH[0]}"
local line="$1"

# skip to the file extension
# we need to do this because the file path
# could already contain ":" or more likely "-"
line="$(printf '%s' "$line" | grep -Eo '(\.(cpp|h|c).*)')"

# then match the first character after the digit
[[ "$line" =~ [^a-zA-Z0-9/.] ]] && printf '%s' "${BASH_REMATCH[0]}"
}

function _chop_grep_line() {
Expand Down
3 changes: 3 additions & 0 deletions lib/test/unit/audit_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ else
echo "OK"
fi

assert_eq "$(_get_grep_context 'src/external/DDNetPP-bots/src/twbl/teeworlds/base/system.cpp:6: * @ingroup Filesystem')" ":" "detect correct grep context :"
assert_eq "$(_get_grep_context 'src/external/DDNetPP-bots/src/twbl/teeworlds/base/system.cpp-5- *')" "-" "detect correct grep context -"

log -n "audit_code.sh [_chop_grep_line ':'] ... "

if ! diff <(_chop_grep_line 'src/game/client/gameclient.cpp:580: // render all systems') \
Expand Down

0 comments on commit b756d9f

Please sign in to comment.