Escaped HTML special characters and truncated descriptions to 100 GH-13

This commit is contained in:
2023-02-21 23:04:52 -06:00
parent 868646845a
commit 657000ddd6
2 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using AutoMapper; using AutoMapper;
using System.Net;
using YABA.API.ViewModels; using YABA.API.ViewModels;
using YABA.API.ViewModels.Bookmarks; using YABA.API.ViewModels.Bookmarks;
using YABA.API.ViewModels.Tags; using YABA.API.ViewModels.Tags;
@ -13,7 +14,9 @@ namespace YABA.API.Settings
public AutoMapperProfile() public AutoMapperProfile()
{ {
CreateMap<UserDTO, UserResponse>(); CreateMap<UserDTO, UserResponse>();
CreateMap<BookmarkDTO, BookmarkResponse>(); CreateMap<BookmarkDTO, BookmarkResponse>()
.ForMember(dest => dest.Title, opt => opt.MapFrom(src => WebUtility.HtmlDecode(src.Title)))
.ForMember(dest => dest.Description, opt => opt.MapFrom(src => WebUtility.HtmlDecode(src.Description)));
CreateMap<WebsiteMetaDataDTO, GetWebsiteMetaDataResponse>(); CreateMap<WebsiteMetaDataDTO, GetWebsiteMetaDataResponse>();
CreateMap<BookmarkDTO, PatchBookmarkRequest>(); CreateMap<BookmarkDTO, PatchBookmarkRequest>();
CreateMap<PatchBookmarkRequest, UpdateBookmarkRequestDTO>(); CreateMap<PatchBookmarkRequest, UpdateBookmarkRequestDTO>();

View File

@ -15,7 +15,7 @@ export function Bookmark(props) {
</Col> </Col>
<Col xs={11}> <Col xs={11}>
<a href="#" style={{textDecoration: "none"}}>{props.bookmark.title}</a> <a href="#" style={{textDecoration: "none"}}>{props.bookmark.title}</a>
<div className="font-weight-normal">{props.bookmark.description.substring(0, 100)}</div> <div className="font-weight-normal">{`${props.bookmark.description.substring(0, 97)}${props.bookmark.description.length >= 97 ? "..." : ""}`}</div>
<div> <div>
{ {
props.bookmark.tags.map((tag) => <Tag key={props.bookmark.id-tag.id} tag={tag} />) props.bookmark.tags.map((tag) => <Tag key={props.bookmark.id-tag.id} tag={tag} />)