Skip to content

Commit 57a4371

Browse files
authored
PRO-8268: do the URL encoding work before Astro.redirect sees the URL (#5061)
1 parent e4eea18 commit 57a4371

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
* Custom operations registered with `addCreateWidgetOperation` can now specify an `ifTypesIntersect` property containing an array of widget type names. If the area in question allows at least one, the operation is offered.
88

9+
### Changes
10+
11+
* Redirects to URLs containing accent marks and other non-ascii characters now behave as expected with Astro. Pre-encoding the URLs exactly the way `res.redirect` would before passing them to Astro prevents an error in Astro and allows the redirect to succeed.
12+
913
## 4.21.0 (2025-09-03)
1014

1115
### Adds

modules/@apostrophecms/area/ui/apos/components/AposAreaContextualMenu.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ export default {
202202
return [];
203203
}
204204
const menu = [ ...this.contextMenuOptions.menu ];
205-
const createWidgetOperations = filterCreateWidgetOperations(this.moduleOptions, this.options);
205+
const createWidgetOperations = filterCreateWidgetOperations(
206+
this.moduleOptions,
207+
this.options
208+
);
206209
for (const createWidgetOperation of createWidgetOperations) {
207210
menu.unshift({
208211
type: 'operation',

modules/@apostrophecms/express/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const expressBearerToken = require('express-bearer-token');
159159
const cors = require('cors');
160160
const Promise = require('bluebird');
161161
const expressCacheOnDemand = require('express-cache-on-demand');
162+
const encodeUrl = require('encodeurl');
162163

163164
module.exports = {
164165
async init(self) {
@@ -275,7 +276,11 @@ module.exports = {
275276
// not us
276277
// Per Express handling of 1 arg versus 2
277278
const status = args.length > 1 ? args[0] : 302;
278-
const url = args[args.length - 1];
279+
let url = args[args.length - 1];
280+
// The URL needs to be encoded exactly as Express would do it,
281+
// so that frontends like Astro (which don't do it for us) don't bomb
282+
// attempting to issue the redirect
283+
url = encodeUrl(url);
279284
return res.send({
280285
redirect: true,
281286
url,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"csv-parse": "^5.6.0",
7272
"dayjs": "^1.9.8",
7373
"dompurify": "^3.2.5",
74+
"encodeurl": "^2.0.0",
7475
"express": "^4.16.4",
7576
"express-bearer-token": "^3.0.0",
7677
"express-cache-on-demand": "^1.0.3",
@@ -143,4 +144,4 @@
143144
"browserslist": [
144145
"ie >= 10"
145146
]
146-
}
147+
}

0 commit comments

Comments
 (0)