Avoid regex pattern matching for simple String replacement steps

Issue: SPR-17279
This commit is contained in:
Juergen Hoeller
2018-09-17 14:22:19 +02:00
parent cc87fbcb7f
commit 34663300a6
13 changed files with 61 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import java.util.UUID;
import org.springframework.lang.Nullable;
import org.springframework.util.IdGenerator;
import org.springframework.util.JdkIdGenerator;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.sockjs.transport.TransportType;
import org.springframework.web.util.UriComponentsBuilder;
@@ -68,7 +69,7 @@ public class SockJsUrlInfo {
public String getSessionId() {
if (this.sessionId == null) {
this.sessionId = getUuid().toString().replace("-","");
this.sessionId = StringUtils.delete(getUuid().toString(), "-");
}
return this.sessionId;
}

View File

@@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Represents a SockJS frame. Provides factory methods to create SockJS frames.
@@ -142,7 +143,9 @@ public class SockJsFrame {
if (result.length() > 80) {
result = result.substring(0, 80) + "...(truncated)";
}
return "SockJsFrame content='" + result.replace("\n", "\\n").replace("\r", "\\r") + "'";
result = StringUtils.replace(result, "\n", "\\n");
result = StringUtils.replace(result, "\r", "\\r");
return "SockJsFrame content='" + result + "'";
}