Scalatex
Scalatex copied to clipboard
Site.renderTo writes junk bytes at the end of HTML files.
When I use Site.renderTo, HTML pages are rendered, but they contain junk bytes at the end of the file, after the closing </html>. This is because this line:
https://github.com/lihaoyi/Scalatex/blob/c50c910460580327f50fc3b43d2176c7a5e57c01/site/src/main/scala/scalatex/site/Site.scala#L132
returns a ByteBuffer whose internal capacity is greater than the actually written content. Therefore, writing bytes.array() at
https://github.com/lihaoyi/Scalatex/blob/c50c910460580327f50fc3b43d2176c7a5e57c01/site/src/main/scala/scalatex/site/Site.scala#L134
also writes junk bytes of the internal array that were never written.
A solution is to slice the array before giving it to write.over:
write.over(outputRoot/path,
bytes.array().slice(bytes.position(), bytes.limit()), createFolders = true)
Fixed in the version I maintain: https://github.com/openmole/scalatex/commit/3dbedae4ce81c76495e44a2aec7f20cd701c7754