-
Type:
Bug
-
Status: Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 0.2.6
-
Fix Version/s: 0.2.7
-
Labels:None
If in the css file we put a negative value to sprite-margin-XXXX it throws a ArrayIndexOutOfBoundsException.
I tried to fix it in source code. My changes affects the 3 files:
org.carrot2.labs.smartsprites.message.Message
----------------------------------------------
-added in MessageType :
CANNOT_PARSE_NEGATIVE_MARGIN_VALUE("Cannot parse negative margin value: %s. Using '0'"),
org.carrot2.labs.smartsprites.SpriteImageDirective
-------------------------------------------------------
-added a parameter "MessageLog messageLog" in SpriteImageDirective function. So the functions is like:
public SpriteImageDirective(String id, String imageUrl, SpriteImageLayout layout,
SpriteImageFormat format, Ie6Mode ie6Mode, Color matteColor, SpriteUidType uidType, MessageLog messageLog)
org.carrot2.labs.smartsprites.SpriteLayoutProperties
-----------------------------------------------------
-changes in the 2 constructors:
public SpriteLayoutProperties(SpriteAlignment alignment, int marginLeft,
int marginRight, int marginTop, int marginBottom, MessageLog messageLog)
{
this.alignment = alignment;
if(marginLeft<0)
else
{ this.marginLeft = marginLeft; }if(marginRight<0)
{ messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, marginRight); this.marginRight = 0; }else
{ this.marginRight = marginRight; }if(marginTop<0)
{ messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, marginTop); this.marginTop = 0; }else
{ this.marginTop = marginTop; }if(marginBottom<0)
{ messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, marginBottom); this.marginBottom = 0; }else
{ this.marginBottom = marginBottom; }}
/**
- Creates an instance with default values.
*/
SpriteLayoutProperties(SpriteImageLayout layout, MessageLog messageLog) { this(getDefaultAlignment(layout), 0, 0, 0, 0, messageLog); }
-added the parameter in the call in 'parse' method (line 129):
return parse(directiveString, spriteImageLayout, new SpriteLayoutProperties(
spriteImageLayout, messageCollector), messageCollector);
-added the parameter in the call in 'parse' method (line 181):
return new SpriteLayoutProperties(alignment, marginLeft, marginRight, marginTop,
marginBottom);
-Change the try/catch content in getMargin metod (line 246):
try
{
int value = Integer.parseInt(marginValue);
if (value<0)
else
{ return value; } }
catch (final NumberFormatException e)