Permalink
Browse files

Simplify, and add a git-specific solution.

  • Loading branch information...
Andy Chu
Andy Chu committed Sep 20, 2017
1 parent a089617 commit 4c353d15377fc87c8a6721d095cbbd54347a32b0
Showing with 46 additions and 16 deletions.
  1. +43 −0 git-changelog/demo-nul.sh
  2. +3 −16 git-changelog/demo.sh
View
@@ -0,0 +1,43 @@
#!/bin/bash
#
# Alternative solution using pairs of %x00, which is specific to git.
#
# Usage:
# ./demo-nul.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
escape-segments0() {
python -c '
import cgi, re, sys
print re.sub(
r"\x00(.*)\x00",
lambda match: cgi.escape(match.group(1)),
sys.stdin.read())
'
}
git-log-html0() {
echo '<table>'
# - a trick for HTML escaping (avoid XSS): surround %s with unlikely bytes,
# 0x01 and 0x02. Then pipe Python to escape.
local format='
<tr>
<td> <a href="https://github.com/oilshell/blog-code/commit/%H">%h</a> </td>
<td>%x00%s%x00</td>
</tr>'
git log -n 5 --pretty="format:$format" | escape-segments0
echo '</table>'
}
write-file0() {
git-log-html0 > git-log0.html
echo "Wrote git-log0.html"
}
"$@"
View
@@ -17,31 +17,18 @@ print re.sub(
}
git-log-html() {
cat <<EOF
<!DOCTYPE html>
<html>
<head>
<title>Git Log</title>
</head>
<body>
<h1>Git Log</h1>
<table width="100%">
EOF
echo '<table>'
# - a trick for HTML escaping (avoid XSS): surround %s with unlikely bytes,
# \x00 and \x01. Then pipe Python to escape.
# 0x01 and 0x02. Then pipe Python to escape.
local format=$'
<tr>
<td> <a href="https://github.com/oilshell/blog-code/commit/%H">%h</a> </td>
<td>\x01%s\x02</td>
</tr>'
git log -n 5 --pretty="format:$format" | escape-segments
cat <<EOF
</table>
</body>
</html>
EOF
echo '</table>'
}
# Remember: http://www.oilshell.org/blog/2017/08/12.html

0 comments on commit 4c353d1

Please sign in to comment.