mediawiki.action.edit.preview: Substitute $ by $$ in newSubStr for .replace()
authorFomafix <fomafix@googlemail.com>
Wed, 2 Nov 2016 16:58:58 +0000 (17:58 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 4 Nov 2016 17:28:09 +0000 (17:28 +0000)
The newSubStr parameter of .replace() can contain replacement patterns
starting with $. The pattern $$ inserts a single $.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter

Bug: T149816
Change-Id: I69619357b7091e302e50398c6258a321346a6240

resources/src/mediawiki.action/mediawiki.action.edit.preview.js

index 3b19b35..f26c336 100644 (file)
                                        $( '<span>' ).addClass( 'comment' ).html(
                                                // There is no equivalent to rawParams
                                                mw.message( 'parentheses' ).escaped()
-                                                       .replace( '$1', parse.parsedsummary )
+                                                       // .replace() use $ as start of a pattern.
+                                                       // $$ is the pattern for '$'.
+                                                       // The inner .replace() duplicates any $ and
+                                                       // the outer .replace() simplifies the $$.
+                                                       .replace( '$1', parse.parsedsummary.replace( /\$/g, '$$$$' ) )
                                        )
                                );
                        }