How to Quickly and Correctly Generate a Git Log in HTML
Reinventing escaping over and over again (which  bash scripts in particular seem to encourage) is a suckers game. It&#x27;s difficult to get right and if you&#x27;re constantly redoing it you&#x27;re eventually going to make a mistake. I&#x27;ve worked in web security and it&#x27;s sad to see how likely it is for people with good intentions to mess this up. I&#x27;m glad the author basically came to this conclusion.<p>The winning strategy is to use a library&#x2F;framework&#x2F;whatever for embedding user-provided content into HTML. Sane HTML template libraries will do this. That library has had more time to get it right. Furthermore a well designed API will clearly indicate what is trusted vs. untrusted data and all untrusted data is properly encoded before being embedded. See the &quot;Security Model&quot; section of golangs HTML templates below.<p>An alternative to using the git tools which is appropriate for serious work (shell pipelines are great for prototyping) is libgit2. It has bindings for many languages. It&#x27;s very easy to use (sometimes (not always) easier than the CLI) and often much higher performance vs. big shell pipelines (operating on text gets slow pretty fast, and often you end up using xargs...)<p>An example set of tools: <a href="https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;html&#x2F;template&#x2F;" rel="nofollow">https:&#x2F;&#x2F;golang.org&#x2F;pkg&#x2F;html&#x2F;template&#x2F;</a> + <a href="https:&#x2F;&#x2F;github.com&#x2F;libgit2&#x2F;git2go" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;libgit2&#x2F;git2go</a> .<p>It&#x27;s not as succinct as a bash script but it&#x27;s easier to build something that&#x27;s correct. Use the shell to prototype, build it right in a saner environment.