Skip to content

Commit

Permalink
URL encode tags and URLs in stomp topics
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Dec 15, 2023
1 parent 413eace commit 5d0e747
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/jasper/component/MessagesImplStomp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

@Profile("!no-websocket")
Expand All @@ -24,12 +27,13 @@ public void updateRef(Ref ref) {
stomp.convertAndSend("/topic/ref/" + (isNotBlank(ref.getOrigin()) ? ref.getOrigin() : "default") + "/" + ref.getUrl(), mapper.domainToUpdateDto(ref));
if (ref.getTags() != null)
for (var tag : ref.getTags()) {
// TODO: workaround +_ in destination
stomp.convertAndSend("/topic/tag/" + tag.replace('_', '>').replace('+', '<'), tag);
var encodedTag = URLEncoder.encode(tag, StandardCharsets.UTF_8);
stomp.convertAndSend("/topic/tag/" + encodedTag, tag);
}
if (ref.getSources() != null)
for (var source : ref.getSources()) {
stomp.convertAndSend("/topic/response/" + source, ref.getUrl());
var encodedSource = URLEncoder.encode(source, StandardCharsets.UTF_8);
stomp.convertAndSend("/topic/response/" + encodedSource, ref.getUrl());
}
}
}

0 comments on commit 5d0e747

Please sign in to comment.