From f043975fc897444880e7d21ca45bdf65b24e813d Mon Sep 17 00:00:00 2001 From: mindless Date: Tue, 16 Mar 2010 16:14:27 +0000 Subject: [PATCH] [HUDSON-5941] [HUDSON-5944] MarkupText.toString(boolean) was ignoring the preEscape parameter when no markup tags were added. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@28737 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/MarkupText.java | 4 ++-- core/src/test/java/hudson/MarkupTextTest.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/MarkupText.java b/core/src/main/java/hudson/MarkupText.java index 2a7b813659..28d88e18a4 100644 --- a/core/src/main/java/hudson/MarkupText.java +++ b/core/src/main/java/hudson/MarkupText.java @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi + * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -267,7 +267,7 @@ public class MarkupText extends AbstractMarkupText { */ public String toString(boolean preEscape) { if(tags.isEmpty()) - return Util.escape(text); // the most common case + return preEscape? Util.xmlEscape(text) : Util.escape(text); // the most common case Collections.sort(tags); diff --git a/core/src/test/java/hudson/MarkupTextTest.java b/core/src/test/java/hudson/MarkupTextTest.java index dbed218fc5..1b5455cf94 100644 --- a/core/src/test/java/hudson/MarkupTextTest.java +++ b/core/src/test/java/hudson/MarkupTextTest.java @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi + * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -94,5 +94,12 @@ public class MarkupTextTest extends TestCase { assertEquals("&& &",text.toString(false)); } + public void testPreEscape() { + MarkupText text = new MarkupText("Line\n2 & 3\n\n"); + assertEquals("Line\n2 & 3\n<End>\n", text.toString(true)); + text.addMarkup(4, "
"); + assertEquals("Line
\n2 & 3\n<End>\n", text.toString(true)); + } + private static final Pattern pattern = Pattern.compile("issue #([0-9]+)"); }