Don't crash if email address has sub-address with special characters (#44)

This commit is contained in:
Olav Sundfør 2025-06-18 22:52:14 +02:00 committed by GitHub
parent 0e77c35fb2
commit 4e0ea3b324
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -1,8 +1,8 @@
// deno-lint-ignore-file ban-ts-comment
import { STATUS_CODE } from "$fresh/server.ts";
import "jsr:@std/dotenv/load";
import { encodeHex } from "jsr:@std/encoding/hex";
import { getHostUrl } from "../utils.ts";
import { STATUS_CODE } from "$fresh/server.ts";
const config = {
clientId: Deno.env.get("VIPPS_CLIENT_ID"),
@ -50,6 +50,11 @@ const getAccessToken = async function () {
export const createAgreement = async function (email: string) {
const token = await getAccessToken();
const amount = 5000; // 50 NOK
// in case of special characters, like sub-addresses added
// with +, e.g. "name+subscriptions@domain.com"
const urlEncodedEmail = encodeURIComponent(email);
const redirectUrl = `${getHostUrl()}/donations-success?urlEncodedEmail=${urlEncodedEmail}`;
const response = await fetch(`${config.baseUrl}/recurring/v3/agreements/`, {
method: "POST",
// @ts-ignore
@ -74,7 +79,7 @@ export const createAgreement = async function (email: string) {
currency: "NOK",
},
// email is used to identify the user in the success page
merchantRedirectUrl: `${getHostUrl()}/donations-success?email=${email}`,
merchantRedirectUrl: redirectUrl,
merchantAgreementUrl: `${getHostUrl()}`,
productName: "Månedlig støtte til NRSS",
}),

View File

@ -5,7 +5,9 @@ import { validateEmail } from "../lib/utils.ts";
export const handler: Handlers = {
async GET(request, ctx) {
const url = new URL(request.url);
const email = url.searchParams.get("email");
const urlEncodedEmail = url.searchParams.get("urlEncodedEmail");
const email = urlEncodedEmail ? decodeURIComponent(urlEncodedEmail) : null;
if (!email) {
console.error("Missing email in query params", request.url);
return Response.redirect("/donations-error");
@ -34,9 +36,7 @@ export const handler: Handlers = {
export default function () {
return (
<div className="my-16 text-center flex flex-col items-center min-h-screen ">
<h1 className="text-6xl mb-8">
🙏🌟😊💖
</h1>
<h1 className="text-6xl mb-8">🙏🌟😊💖</h1>
<p className="text-4xl mb-4">
Tusen takk! Jeg er veldig takknemlig for all støtte.
</p>