Skip to content

Commit

Permalink
Escape characters that can broke json payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Walkyst committed Oct 22, 2021
1 parent 07f96f1 commit 1500fb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ public ExtendedHttpConfigurable getHttpConfiguration() {
*/
@Override
public AudioItem loadSearchMusicResult(String query, Function<AudioTrackInfo, AudioTrack> trackFactory) {
log.debug("Performing a search music with query {}", query);
String escapedQuery = query.replaceAll("\"|\\\\", "");
log.debug("Performing a search music with query {}", escapedQuery);

try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
HttpPost post = new HttpPost(MUSIC_SEARCH_URL);
StringEntity payload = new StringEntity(String.format(MUSIC_SEARCH_PAYLOAD, query.replace("\"", "\\\"")), "UTF-8");
StringEntity payload = new StringEntity(String.format(MUSIC_SEARCH_PAYLOAD, escapedQuery), "UTF-8");
post.setHeader("Referer", "music.youtube.com");
post.setEntity(payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public ExtendedHttpConfigurable getHttpConfiguration() {
*/
@Override
public AudioItem loadSearchResult(String query, Function<AudioTrackInfo, AudioTrack> trackFactory) {
log.debug("Performing a search with query {}", query);
String escapedQuery = query.replaceAll("\"|\\\\", "");
log.debug("Performing a search with query {}", escapedQuery);

try (HttpInterface httpInterface = httpInterfaceManager.getInterface()) {
HttpPost post = new HttpPost(SEARCH_URL);
StringEntity payload = new StringEntity(String.format(SEARCH_PAYLOAD, query.replace("\"", "\\\"")), "UTF-8");
StringEntity payload = new StringEntity(String.format(SEARCH_PAYLOAD, escapedQuery), "UTF-8");
post.setEntity(payload);

try (CloseableHttpResponse response = httpInterface.execute(post)) {
HttpClientTools.assertSuccessWithContent(response, "search response");

Expand Down

0 comments on commit 1500fb1

Please sign in to comment.