Skip to content

Commit

Permalink
Minimize element.substring errors + fix math
Browse files Browse the repository at this point in the history
This will prevent stacktraces / failure to run if substrings are used
with really *really* wrong input indexes. (There are situations where it
can happen out of the scripters control, can't blame them)
It also corrects the counting of the end index (the character at
endIndex is not included in Java)... it should be in dScript. This way
substring[1,1] returns one letter rather than nothing at all. This is
generally what people logically expect to occur, though there may be
trouble with 'endIndex - startIndex' not being equal to the returned
length... anyone who gets that far in a calculation can figure out to
add 1.
  • Loading branch information
mcmonkey4eva committed Nov 16, 2013
1 parent 1251c4a commit b4ccaae
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -671,11 +671,13 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
int beginning_index = Integer.valueOf(attribute.getContext(1).split(",")[0]) - 1;
int ending_index;
if (attribute.getContext(1).split(",").length > 1)
ending_index = Integer.valueOf(attribute.getContext(1).split(",")[1]) - 1;
ending_index = Integer.valueOf(attribute.getContext(1).split(",")[1]);
else
ending_index = element.length();
if (beginning_index < 0) beginning_index = 0;
if (beginning_index > element.length()) beginning_index = element.length();
if (ending_index > element.length()) ending_index = element.length();
if (ending_index < beginning_index) ending_index = beginning_index;
return new Element(element.substring(beginning_index, ending_index))
.getAttribute(attribute.fulfill(1));
}
Expand Down

0 comments on commit b4ccaae

Please sign in to comment.