File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -112,11 +112,19 @@ class Result {
112112 }
113113}
114114
115+ /**
116+ * `String.replace()` converts '$$' to '$', so we must escape each '$' as '$$';
117+ * but because we’re using `String.replace()` to do it, we must use '$$$'!
118+ */
119+ function escapeForStringReplace ( string ) {
120+ return string . replace ( / \$ / g, '$$$' ) ;
121+ }
122+
115123function insertIntoIndexHTML ( html , head , body ) {
116- html = html . replace ( "<!-- EMBER_CLI_FASTBOOT_BODY -->" , body ) ;
124+ html = html . replace ( "<!-- EMBER_CLI_FASTBOOT_BODY -->" , escapeForStringReplace ( body ) ) ;
117125
118126 if ( head ) {
119- html = html . replace ( "<!-- EMBER_CLI_FASTBOOT_HEAD -->" , head ) ;
127+ html = html . replace ( "<!-- EMBER_CLI_FASTBOOT_HEAD -->" , escapeForStringReplace ( head ) ) ;
120128 }
121129
122130 return html ;
Original file line number Diff line number Diff line change @@ -81,5 +81,23 @@ describe('Result', function() {
8181 } ) ;
8282 } ) ;
8383 } ) ;
84+
85+ describe ( 'when the document has special-case content' , function ( ) {
86+ var BODY = '<h1>A special response document: $$</h1>' ;
87+
88+ beforeEach ( function ( ) {
89+ doc . body . appendChild ( doc . createRawHTMLSection ( BODY ) ) ;
90+
91+ result . _fastbootInfo . response . statusCode = 418 ;
92+ result . _finalize ( ) ;
93+ } ) ;
94+
95+ it ( 'it should handle \'$$\' correctly (due to `String.replace()` gotcha)' , function ( ) {
96+ return result . html ( )
97+ . then ( function ( result ) {
98+ expect ( result ) . to . include ( BODY ) ;
99+ } ) ;
100+ } ) ;
101+ } ) ;
84102 } ) ;
85103} ) ;
You can’t perform that action at this time.
0 commit comments