Fix escaping URL content that contains special characters.

This commit is contained in:
Kavin 2023-01-14 00:29:30 +00:00
parent e8686c3e97
commit 2a0ae093ea
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
1 changed files with 10 additions and 10 deletions

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;
@ -75,7 +70,7 @@ public class ChannelHelpers {
SyndPerson person = new SyndPersonImpl();
SyndContent content = new SyndContentImpl();
SyndContent thumbnail = new SyndContentImpl();
person.setName(channel.getUploader());
person.setUri(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId());
entry.setAuthors(Collections.singletonList(person));
@ -87,12 +82,17 @@ 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);
entry.setContents(List.of(thumbnail, content));
return entry;
}
}