From d60e556b5b56281ba7c4269209913a74de759876 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Mon, 29 Jul 2019 11:29:24 -0700 Subject: [PATCH] prevent URL length limit errors Closes #829 --- lib/routing.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/routing.js b/lib/routing.js index f28d05d..a255da5 100644 --- a/lib/routing.js +++ b/lib/routing.js @@ -3,6 +3,7 @@ import url from 'url' import { escapeHtml } from './util' +const URL_LIMIT = 4e3 const mapper = new Morph({ types: { bool: v => { @@ -29,7 +30,12 @@ const mapper = new Morph({ encode: v => { if (v == null) return undefined try { - return encodeURIComponent(v) + const encoded = encodeURIComponent(v) + if (encoded.length > URL_LIMIT) { + // soft prevent URL length limit errors https://github.com/dawnlabs/carbon/issues/829 + return encodeURIComponent(v.slice(0, URL_LIMIT / 2)) + } + return encoded } catch (e) { return v }