-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration entry to allow adding additional elements.
- Loading branch information
Showing
11 changed files
with
288 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hudson.markup; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class ElementInfo { | ||
public final String tag; | ||
public final List<String> attributes; | ||
|
||
public ElementInfo(String tag, List<String> attributes) { | ||
this.tag = tag; | ||
this.attributes = attributes; | ||
} | ||
|
||
public ElementInfo(String tag, String[] attributes) { | ||
this.tag = tag; | ||
this.attributes = Arrays.asList(attributes); | ||
} | ||
|
||
public ElementInfo(String tag) { | ||
this.tag = tag; | ||
this.attributes = new ArrayList<String>(); | ||
} | ||
|
||
public boolean equals(ElementInfo other) { | ||
if (other.tag.equals(this.tag) && other.attributes.equals(this.attributes)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public String dump() { | ||
return this.toString() + "\n " + tag + "\n " + attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package hudson.markup; | ||
|
||
import java.util.ArrayList; | ||
import java.text.ParseException; | ||
import java.util.Iterator; | ||
|
||
import hudson.markup.ElementInfo; | ||
|
||
|
||
public class ParseAdditionalAllowed implements Iterable<ElementInfo> { | ||
private ArrayList<ElementInfo> elements = new ArrayList<ElementInfo>(); | ||
|
||
public static ArrayList<ElementInfo> validateAdditionalAllowed(final String additionalAllowed) throws ParseException { | ||
ArrayList<ElementInfo> elements = new ArrayList<ElementInfo>(); | ||
String tag = null; | ||
ArrayList<String> attributes = null; | ||
|
||
if (additionalAllowed.trim().equals("")) { | ||
return elements; | ||
} | ||
|
||
if (additionalAllowed.endsWith(",")) { | ||
throw new java.text.ParseException("Could not parse: '" + additionalAllowed + "', found trailing ','", 0); | ||
} | ||
|
||
for ( String word : additionalAllowed.split("(?!^)\\b") ) { | ||
// System.out.println("word: '" + word + "'"); | ||
word = word.trim(); | ||
|
||
if (word.startsWith(",")) { | ||
if (!word.equals(",")) { | ||
throw new java.text.ParseException("Could not parse: '" + additionalAllowed + "', unexpected '" + word + "'", 0); | ||
} | ||
|
||
if (attributes == null ) { | ||
elements.add(new ElementInfo(tag)); | ||
// System.out.println(tag + attributes.toString()); | ||
tag = null; | ||
} | ||
} else if (word.startsWith("[")) { | ||
if (!word.equals("[") || attributes != null) { | ||
throw new java.text.ParseException("Could not parse: '" + additionalAllowed + "', unexpected '" + word + "'", 0); | ||
} | ||
|
||
attributes = new ArrayList<String>(); | ||
// System.out.println("Start attr:" + tag + attributes.toString()); | ||
} else if (word.startsWith("]")) { | ||
if (!(word.equals("]") || word.equals("],")) || attributes == null) { | ||
throw new java.text.ParseException("Could not parse: '" + additionalAllowed + "', unexpected '" + word + "'", 0); | ||
} | ||
|
||
elements.add(new ElementInfo(tag, attributes)); | ||
// System.out.println(tag + attributes.toString()); | ||
tag = null; | ||
attributes = null; | ||
} else { | ||
// System.out.println("not delim: " + word); | ||
if ( attributes != null ) { | ||
attributes.add(word); | ||
} else { | ||
tag = word; | ||
} | ||
} | ||
} | ||
|
||
if (tag != null) { | ||
elements.add(new ElementInfo(tag)); | ||
// System.out.println(tag + attributes.toString()); | ||
} | ||
|
||
if (attributes != null) { | ||
throw new java.text.ParseException("Could not parse: '" + additionalAllowed + "', expected ']'", 0); | ||
} | ||
|
||
return elements; | ||
} | ||
|
||
public ParseAdditionalAllowed(final String additionalAllowed) { | ||
try { | ||
this.elements = validateAdditionalAllowed(additionalAllowed); | ||
} catch (ParseException ex) { | ||
// This should never happen as validateAdditionalAllowed should have been called by Jenkins | ||
System.err.println("Plugin initialization error:" + ex); | ||
} | ||
} | ||
|
||
@Override | ||
public Iterator<ElementInfo> iterator() { | ||
return this.elements.iterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/hudson/markup/RawHtmlMarkupFormatter/config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
blurb=Treats the text as HTML and sanitizes it, removing potentially unsafe elements like <code><script></code>. | ||
disableSyntaxHighlighting=Disable syntax highlighting | ||
additionalAllowed=Allow additional elements. The format is "tag1,tag2[attribute1,attribute2,...],tag3...", e.g. "span[title],font[color]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.