File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/// <reference path="../node_modules/@cloudflare/workers-types/index.d.ts" />
22
3- import { getProjectInfo } from './utils' ;
3+ import { encodeHTML , getProjectInfo } from './utils' ;
44
55type Env = Record < 'API_TOKEN' , string > ;
66type Data = Record < string , unknown > ;
@@ -54,15 +54,15 @@ export const onRequest: PgFunction = async function (context) {
5454 . replace (
5555 / t i t l e " c o n t e n t = " L i v e C o d e s " / g,
5656 `title" content="${
57- ! title || title === 'Untitled Project' ? 'LiveCodes' : title + ' - LiveCodes'
57+ ! title || title === 'Untitled Project' ? 'LiveCodes' : encodeHTML ( title ) + ' - LiveCodes'
5858 } "`,
5959 )
6060 . replace (
6161 / 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,
6262 `content="${
6363 ! title && ! description
6464 ? 'A Code Playground That Just Works!'
65- : description || 'A project on LiveCodes.'
65+ : encodeHTML ( description || 'A project on LiveCodes.' )
6666 } "`,
6767 )
6868 . 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 } "` )
@@ -83,7 +83,7 @@ export const onRequest: PgFunction = async function (context) {
8383
8484 context . waitUntil ( logToAPI ( context ) ) ;
8585 return response ;
86- } catch ( err ) {
86+ } catch ( err : any ) {
8787 context . data = {
8888 ...data ,
8989 ok : false ,
Original file line number Diff line number Diff line change @@ -73,3 +73,11 @@ export const getProjectInfo = async (url: URL): Promise<ProjectInfo> => {
7373 description : '' ,
7474 } ;
7575} ;
76+
77+ export const encodeHTML = ( html : string ) =>
78+ html
79+ . replace ( / & / g, '&' )
80+ . replace ( / < / g, '<' )
81+ . replace ( / > / g, '>' )
82+ . replace ( / ' / g, ''' )
83+ . replace ( / " / g, '"' ) ;
You can’t perform that action at this time.
0 commit comments