Skip to content

Commit

Permalink
Convert to fullUrl to URL object
Browse files Browse the repository at this point in the history
This should be a safer way of handling URL parsing.
  • Loading branch information
fritz-fritz committed May 31, 2024
1 parent 6f08f6e commit e2c2e40
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions routes/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ router.post('/template', async (req, res) => {
router.post('/', async (req, res) => {
const formData = req.body;

let fullUrl = `${req.protocol}://${req.get('Host')}${req.originalUrl.split("/settings")[0]}`;
let fullUrl = new URL(`${req.protocol}://${req.get('Host')}${req.originalUrl}`);
if (req.get('Referer')) {
fullUrl = req.get('Referer').split("/settings")[0];
fullUrl = new URL(req.get('Referer'));
}
formData['ghosler.url'] = fullUrl;
fullUrl.pathname = fullUrl.pathname.split('/settings')[0];
fullUrl.search = ''; // drops any query parameters
formData['ghosler.url'] = fullUrl.toString();

const result = await ProjectConfigs.update(formData);
const configs = await ProjectConfigs.all();
Expand Down

0 comments on commit e2c2e40

Please sign in to comment.