Skip to content

Commit 5eda9ab

Browse files
committed
Remove newlines in addition to escaping quotes.
1 parent 9c62c0e commit 5eda9ab

2 files changed

Lines changed: 5 additions & 35 deletions

File tree

gradle/sava.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
productDescription=Service Incident Clients
22
javaVersion=25
3-
solanaBOMVersion=25.12.19
3+
solanaBOMVersion=25.14.2

incident-pagerduty/src/main/java/software/sava/incident/pagerduty/event/data/PagerDutyChangeEventPayloadRecord.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package software.sava.incident.pagerduty.event.data;
22

3+
import systems.comodal.jsoniter.JIUtil;
4+
35
import java.math.BigDecimal;
46
import java.math.BigInteger;
57
import java.time.ZonedDateTime;
@@ -57,7 +59,7 @@ public String toString() {
5759
}
5860

5961
static class PagerDutyChangeEventPayloadBuilder implements PagerDutyChangeEventPayload.Builder {
60-
62+
6163
String summary;
6264
String source;
6365
ZonedDateTime timestamp;
@@ -229,38 +231,6 @@ static void appendString(final StringBuilder jsonBuilder, final String field, fi
229231
}
230232
}
231233

232-
private static String escapeQuotes(final String str) {
233-
final char[] chars = str.toCharArray();
234-
final char[] escaped = new char[chars.length << 1];
235-
char c;
236-
for (int escapes = 0, from = 0, dest = 0, to = 0; ; to++) {
237-
if (to == chars.length) {
238-
if (from == 0) {
239-
return str;
240-
} else {
241-
final int len = to - from;
242-
System.arraycopy(chars, from, escaped, dest, len);
243-
dest += len;
244-
return new String(escaped, 0, dest);
245-
}
246-
} else {
247-
c = chars[to];
248-
if (c == '\\') {
249-
escapes++;
250-
} else if (c == '"' && (escapes & 1) == 0) {
251-
final int len = to - from;
252-
System.arraycopy(chars, from, escaped, dest, len);
253-
dest += len;
254-
escaped[dest++] = '\\';
255-
from = to;
256-
escapes = 0;
257-
} else {
258-
escapes = 0;
259-
}
260-
}
261-
}
262-
}
263-
264234
static String toJson(final Map<String, Object> object) {
265235
return object.entrySet().stream().map(entry -> {
266236
final var val = entry.getValue();
@@ -272,7 +242,7 @@ static String toJson(final Map<String, Object> object) {
272242
case Boolean bool -> bool;
273243
case Object obj -> {
274244
final var str = obj.toString();
275-
yield str.indexOf('"') < 0 ? str : escapeQuotes(str);
245+
yield JIUtil.escapeQuotesRemoveNewLinesChecked(str);
276246
}
277247
};
278248
final var key = entry.getKey();

0 commit comments

Comments
 (0)