Skip to content

Commit

Permalink
Properly escape string for regex replace
Browse files Browse the repository at this point in the history
Only escape special replacement syntax such as \0 or & in the
replacement string.

This is a follow-up to 265dc92 which
broke the TOC output.

Closes: https://trac.macports.org/ticket/52924
  • Loading branch information
raimue committed Nov 21, 2016
1 parent aac455f commit fc6576d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions toc-for-chunked.tcl
Expand Up @@ -6,7 +6,7 @@
set file [open "[lindex $argv 0]/index.html"]
regexp {<div class="toc">.+?</div>} [read $file] replacement
close $file
set replacement "<body\\1><div class=\"book\">$replacement"
set replacement "<body\\1><div class=\"book\">[regsub -all {&|\\[0-9]} $replacement {\\&}]"

# Add the table of contents to all other html files.
foreach path [glob -directory [lindex $argv 0] {*.html}] {
Expand All @@ -16,7 +16,7 @@ foreach path [glob -directory [lindex $argv 0] {*.html}] {

set file [open $path r+]
set data [read $file]
regsub {<body([^>]+)>} $data [regsub -all {\W} $replacement {\\&}] data
regsub {<body([^>]+)>} $data $replacement data
regsub {</body>} $data {</div></body>} data
seek $file 0
puts $file $data
Expand Down

0 comments on commit fc6576d

Please sign in to comment.