Skip to content

Commit

Permalink
fix: improve URL validation and handling in router (#96)
Browse files Browse the repository at this point in the history
- Improve URL validation in router.ts
- Fix handling of URLs without specified protocol
  • Loading branch information
7a6163 authored May 17, 2024
1 parent 14a6d20 commit f9c5eb9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/puppeteer-renderer/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import contentDisposition from 'content-disposition'
const router = express.Router()

const urlSchema = yup.object({ url: yup.string().required() }).transform(current => {
if (current.url.includes('://')) {
return current
const regex = /^https?:\/\//;
if (!regex.test(current.url)) {
current.url = `https://${current.url}`
}
current.url = 'https://' + current.url
return current
return current;
})

router.get('/html', async (req, res, next) => {
Expand Down

0 comments on commit f9c5eb9

Please sign in to comment.