File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { getProjectInfo , type Context , type PgFunction } from './utils.ts' ;
1+ import { encodeHTML , getProjectInfo , type Context , type PgFunction } from './utils.ts' ;
22
33export const onRequest : PgFunction = async function ( context ) {
44 const { request, env } = context ;
@@ -48,15 +48,15 @@ export const onRequest: PgFunction = async function (context) {
4848 . replace (
4949 / t i t l e " c o n t e n t = " L i v e C o d e s " / g,
5050 `title" content="${
51- ! title || title === 'Untitled Project' ? 'LiveCodes' : title + ' - LiveCodes'
51+ ! title || title === 'Untitled Project' ? 'LiveCodes' : encodeHTML ( title ) + ' - LiveCodes'
5252 } "`,
5353 )
5454 . replace (
5555 / c o n t e n t = " A C o d e P l a y g r o u n d T h a t J u s t W o r k s ! " / g,
5656 `content="${
5757 ! title && ! description
5858 ? 'A Code Playground That Just Works!'
59- : description || 'A project on LiveCodes.'
59+ : encodeHTML ( description || 'A project on LiveCodes.' )
6060 } "`,
6161 )
6262 . replace ( / c o n t e n t = " h t t p s : \/ \/ l i v e c o d e s .i o \/ " / g, `content="${ request . url } "` )
@@ -77,7 +77,7 @@ export const onRequest: PgFunction = async function (context) {
7777
7878 context . waitUntil ( logToAPI ( context ) ) ;
7979 return response ;
80- } catch ( err ) {
80+ } catch ( err : any ) {
8181 context . data = {
8282 ...data ,
8383 ok : false ,
Original file line number Diff line number Diff line change @@ -80,3 +80,11 @@ export const getProjectInfo = async (url: URL): Promise<ProjectInfo> => {
8080 description : '' ,
8181 } ;
8282} ;
83+
84+ export const encodeHTML = ( html : string ) =>
85+ html
86+ . replace ( / & / g, '&' )
87+ . replace ( / < / g, '<' )
88+ . replace ( / > / g, '>' )
89+ . replace ( / ' / g, ''' )
90+ . replace ( / " / g, '"' ) ;
You can’t perform that action at this time.
0 commit comments