1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Sanitize url to not end with implicit ports

This commit is contained in:
Chocobozzz 2017-12-21 09:56:59 +01:00
parent 6725d05c5f
commit 225a89c2af
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 122 additions and 58 deletions

View file

@ -11,6 +11,26 @@ import * as mkdirp from 'mkdirp'
import { join } from 'path'
import * as pem from 'pem'
import * as rimraf from 'rimraf'
import { URL } from 'url'
function sanitizeUrl (url: string) {
const urlObject = new URL(url)
if (urlObject.protocol === 'https:' && urlObject.port === '443') {
urlObject.port = ''
} else if (urlObject.protocol === 'http:' && urlObject.port === '80') {
urlObject.port = ''
}
return urlObject.href.replace(/\/$/, '')
}
// Don't import remote scheme from constants because we are in core utils
function sanitizeHost (host: string, remoteScheme: string) {
let toRemove = remoteScheme === 'https' ? 443 : 80
return host.replace(new RegExp(`:${toRemove}$`), '')
}
function isTestInstance () {
return process.env.NODE_ENV === 'test'
@ -114,6 +134,8 @@ export {
root,
escapeHTML,
pageToStartAndCount,
sanitizeUrl,
sanitizeHost,
promisify0,
promisify1,