Incorrect regex in TranformInnerHTML still adds newlines after </script> [solution]
|Reported by:||guest||Owned by:||akaEdge|
[Suggested solution below]
There is an incorrect regular expression in TransformInnerHTML.js (nightly version downloaded 23rd August 07) which attempts to compensate for the newlines (returns) added before </script> tags in the source html. The line is line 138 of the .js and reads as follows:
replace(/[\r\n]+<\/script>/g,'\n</script>');//strip returns added into scripts
This doesn't work because the regex section [\r\n]+ doesn't catch the indenting on the </script> line (the prettified html source) and so never matches. Newlines are added every time the source is viewed, eventually making the source code unmanageably long.
The solution is to modify the regex as follows:
replace(/[\r\n]+(\s+)<\/script>/g,'\n$1</script>');//strip returns properly
The suggested solution adds (\s+) (search for the spaces before </script>) and stores the spaces in $1 (in order to preserve the indentation). The replace string \n$1</script> then adds a newline, the preserved indentation, and the close script tag. I have tested this solution with various pages containing scripts, and it works.
- Geoffrey Kantaris