-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#587 fix hashCode NPE for null scalars
- Loading branch information
1 parent
b5450a7
commit f44267a
Showing
3 changed files
with
39 additions
and
18 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 |
---|---|---|
|
@@ -350,7 +350,12 @@ private String indent(final String value, final int indentation) { | |
alignment.append(" "); | ||
spaces--; | ||
} | ||
String[] lines = value.split(System.lineSeparator()); | ||
String[] lines; | ||
if(value == null) { | ||
lines = new String[]{"null"}; | ||
} else { | ||
lines = value.split(System.lineSeparator()); | ||
} | ||
StringBuilder printed = new StringBuilder(); | ||
for(int idx = 0; idx < lines.length; idx++) { | ||
printed.append(alignment); | ||
|
@@ -367,6 +372,7 @@ private String indent(final String value, final int indentation) { | |
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 4.3.1 | ||
* @checkstyle LineLength (100 lines) | ||
*/ | ||
static class Escaped extends BaseScalar { | ||
|
||
|
@@ -384,22 +390,25 @@ static class Escaped extends BaseScalar { | |
} | ||
|
||
@Override | ||
|
||
|
||
public String value() { | ||
final String value = this.original.value(); | ||
String escaped = value; | ||
boolean quoted = (value.startsWith("'") && value.endsWith("'")) | ||
|| (value.startsWith("\"") && value.endsWith("\"")); | ||
final String regex = ".*[?\\-#:>|$%&{}\\[\\]@`!*,'\"]+.*|[ ]+"; | ||
if (!quoted && value.matches(regex)) { | ||
if(value.contains("\"")) { | ||
escaped = "'" + value + "'"; | ||
String toEscape; | ||
if(value == null) { | ||
toEscape = "null"; | ||
} else { | ||
toEscape = value; | ||
} | ||
boolean alreadyEscaped = (toEscape.startsWith("'") && toEscape.endsWith("'")) | ||
|| (toEscape.startsWith("\"") && toEscape.endsWith("\"")); | ||
final String needsEscaping = ".*[?\\-#:>|$%&{}\\[\\]@`!*,'\"]+.*|[ ]+|null"; | ||
if (!alreadyEscaped && toEscape.matches(needsEscaping)) { | ||
if(toEscape.contains("\"")) { | ||
toEscape = "'" + toEscape + "'"; | ||
} else { | ||
escaped = "\"" + value + "\""; | ||
toEscape = "\"" + toEscape + "\""; | ||
} | ||
} | ||
return escaped; | ||
return toEscape; | ||
} | ||
|
||
@Override | ||
|