Skip to content

Commit 520c0b7

Browse files
BATIK-1392: Make font id xml safe
1 parent 94cd2d2 commit 520c0b7

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

batik-svggen/src/main/java/org/apache/batik/svggen/font/SVGFont.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ protected static void writeFontAsSVGFragment(PrintStream ps, Font font, String i
286286
ps.print(SVG_ID_ATTRIBUTE);
287287
ps.print(XML_EQUAL_QUOT);
288288
// ps.print("id=\"");
289-
ps.print(id);
289+
ps.print(encodeEntities(id));
290290
ps.print(XML_CHAR_QUOT);
291291
ps.print(XML_SPACE);
292292
// ps.print("\" ");
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
*/
19+
package org.apache.batik.svggen.font;
20+
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
24+
import java.io.ByteArrayOutputStream;
25+
import java.io.PrintStream;
26+
27+
public class SVGFontTestCase {
28+
@Test
29+
public void testWriteFontAsSVGFragment() throws Exception {
30+
Font font = new Font();
31+
font.read("samples/tests/resources/ttf/glb12.ttf");
32+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
33+
SVGFont.writeFontAsSVGFragment(new PrintStream(bos), font, "abc&", 0,0, false, false);
34+
Assert.assertEquals("<font id=\"abc&amp;\" horiz-adv-x=\"1024\" ><font-face\n" +
35+
" font-family=\"Gladiator\"\n" +
36+
" units-per-em=\"2048\"\n" +
37+
" panose-1=\"2 0 8 3 0 0 0 0 0 0\"\n" +
38+
" ascent=\"1567\"\n" +
39+
" descent=\"-481\"\n" +
40+
" alphabetic=\"0\" />\n" +
41+
"<missing-glyph horiz-adv-x=\"886\" d=\"M68 0V1365H750V0H68ZM136 68H682V1297H136V68Z\" />\n" +
42+
"</font>\n", bos.toString());
43+
}
44+
}

0 commit comments

Comments
 (0)