This repository was archived by the owner on Nov 22, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +5080
-3
lines changed
Expand file tree Collapse file tree 4 files changed +5080
-3
lines changed Original file line number Diff line number Diff line change 55 "main" : " lib/js" ,
66 "scripts" : {
77 "prepublish" : " gulp commonjs" ,
8- "test" : " echo \" Error: no test specified\" && exit 1"
8+ "test" : " echo \" Error: no test specified\" && exit 1" ,
9+ "dev" : " gulp dev" ,
10+ "gulp" : " gulp"
911 },
1012 "repository" : {
1113 "type" : " git" ,
Original file line number Diff line number Diff line change 3939 var NAME = "FontMetrics Library"
4040 var VERSION = "1-2012.0121.1300" ;
4141
42+ var entityMap = {
43+ '&' : '&' ,
44+ '<' : '<' ,
45+ '>' : '>' ,
46+ '"' : '"' ,
47+ "'" : ''' ,
48+ '/' : '/' ,
49+ '`' : '`' ,
50+ '=' : '='
51+ } ;
52+
53+ function escapeHTML ( string ) {
54+ return String ( string ) . replace ( / [ & < > " ' ` = \/ ] / g, function ( s ) {
55+ return entityMap [ s ] ;
56+ } ) ;
57+ }
58+
4259 // if there is no getComputedStyle, this library won't work.
4360 if ( ! document . defaultView . getComputedStyle ) {
4461 throw ( "ERROR: 'document.defaultView.getComputedStyle' not found. This library only works in browsers that can report computed CSS values." ) ;
99116 leadDiv . style . position = "absolute" ;
100117 leadDiv . style . opacity = 0 ;
101118 leadDiv . style . font = fontString ;
102- leadDiv . innerHTML = textstring + "<br/>" + textstring ;
119+ leadDiv . innerHTML = escapeHTML ( textstring ) + "<br/>" + escapeHTML ( textstring ) ;
103120 document . body . appendChild ( leadDiv ) ;
104121
105122 // make some initial guess at the text leading (using the standard TeX ratio)
Original file line number Diff line number Diff line change @@ -18,6 +18,19 @@ renderShapeToSVG = (shape, opts={}) ->
1818 else
1919 throw " Can't render shape of type #{ shape .className } to SVG"
2020
21+ entityMap = {
22+ ' &' : ' &' ,
23+ ' <' : ' <' ,
24+ ' >' : ' >' ,
25+ ' "' : ' "' ,
26+ " '" : ' '' ,
27+ ' /' : ' /' ,
28+ ' `' : ' `' ,
29+ ' =' : ' ='
30+ }
31+
32+ escapeHTML = (string ) -> String (string).replace / [&<>"'`=\/ ] / g , (s ) -> entityMap[s]
33+
2134
2235defineSVGRenderer ' Rectangle' , (shape ) ->
2336 x1 = shape .x
@@ -171,7 +184,7 @@ defineSVGRenderer 'Text', (shape) ->
171184 dy = if i == 0 then 0 else ' 1.2em'
172185 return "
173186 <tspan x='#{ shape .x } ' dy='#{ dy} ' alignment-baseline='text-before-edge'>
174- #{ line}
187+ #{ escapeHTML ( line) }
175188 </tspan>"
176189 ).join (' ' )}
177190 </text>
You can’t perform that action at this time.
0 commit comments