-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathurl-decode.ts
More file actions
28 lines (25 loc) · 857 Bytes
/
url-decode.ts
File metadata and controls
28 lines (25 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { NextFunction, Response } from 'express'
import type { ExtendedRequest } from '@/types'
/**
* Middleware to decode URL-encoded @ symbols.
*
* SharePoint and other systems automatically encode @ symbols to %40,
* which breaks our versioned URLs like /en/enterprise-cloud@latest.
* This middleware decodes @ symbols anywhere in the URL.
*/
export default function urlDecode(req: ExtendedRequest, res: Response, next: NextFunction) {
const originalUrl = req.url
// Only process URLs that contain %40 (encoded @)
if (!originalUrl.includes('%40')) {
return next()
}
try {
// Decode the entire URL, replacing %40 with @
const decodedUrl = originalUrl.replace(/%40/g, '@')
req.url = decodedUrl
return next()
} catch {
// If decoding fails for any reason, continue with original URL
return next()
}
}