Merge pull request #503 from TeamPiped/fix-feeds-encoding

Fix escaping URL content that contains special characters.
This commit is contained in:
Kavin 2023-01-14 00:31:09 +00:00 committed by GitHub
commit 3cae269adb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,19 +1,14 @@
package me.kavin.piped.utils;
import com.rometools.rome.feed.synd.*;
import me.kavin.piped.consts.Constants;
import me.kavin.piped.utils.obj.db.Channel;
import me.kavin.piped.utils.obj.db.Video;
import okhttp3.Request;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.hibernate.StatelessSession;
import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndContentImpl;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndEntryImpl;
import com.rometools.rome.feed.synd.SyndPerson;
import com.rometools.rome.feed.synd.SyndPersonImpl;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@ -87,7 +82,12 @@ public class ChannelHelpers {
String contentText = String.format("Title: %s\nViews: %d\nId: %s\nDuration: %d\nIs YT Shorts: %b", video.getTitle(), video.getViews(), video.getId(), video.getDuration(), video.isShort());
content.setValue(contentText);
String thumbnailContent = String.format("<a href=\"%s\"><img src=\"%s\"/></a>", Constants.FRONTEND_URL + "/watch?v=" + video.getId(), video.getThumbnail());
String thumbnailContent = StringEscapeUtils.escapeXml11(
String.format("<div xmlns=\"http://www.w3.org/1999/xhtml\"><a href=\"%s\"><img src=\"%s\"/></a></div>",
Constants.FRONTEND_URL + "/watch?v=" + video.getId()
, video.getThumbnail()
)
);
thumbnail.setType("xhtml");
thumbnail.setValue(thumbnailContent);