#36 Tolerance against invalid Color String

open
nobody
None
5
2010-02-02
2010-02-02
Anonymous
No

Asume an element defines color like this <foo color="c0c0c0"> ...</foo>
This is clearly an invalid color definition but a very common mistake that someone forgot the # at be beginning.
In this case Lobo uses Color.RED as fallback.

In order to treat this more relaxed I propose the following changes:

a) static field with java.util.regex.Pattern that addresses this issue:
private static final Pattern INVALID_COLOR_PATTERN = Pattern.compile("[a-f0-9]{6}|[a-f0-9]{8}");

b) in method org.lobobrowser.util.gui.ColorFactory.getColor(String):
Color color = (Color) colorMap.get(normalSpec);
if(color == null) {
// my Modification
if (INVALID_COLOR_PATTERN.matcher(normalSpec).matches())
normalSpec = "#" + normalSpec;
//.... continue normally

Probabably the method org.lobobrowser.util.gui.ColorFactory.isColor(String) must be changed in an adequate way.

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks