From 51214177256be1127d793cbc1b40aec04d6856d8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 26 Nov 2013 10:52:03 -0800 Subject: [PATCH] Fix for annoying error message when converting out of range escape https://github.com/fish-shell/fish-shell/issues/1107 --- common.cpp | 2 +- fish_tests.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common.cpp b/common.cpp index 3fce76d66..b7cdedc87 100644 --- a/common.cpp +++ b/common.cpp @@ -1197,7 +1197,7 @@ static size_t read_unquoted_escape(const wchar_t *input, wcstring *result, bool case L'U': { chars=8; - max_val = WCHAR_MAX; + max_val = mini(WCHAR_MAX, 0x10FFFF); // Largest Unicode code point - see #1107 break; } diff --git a/fish_tests.cpp b/fish_tests.cpp index 321d109be..b226d3079 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -144,6 +144,22 @@ static void test_unescape_sane() err(L"In unescaping '%ls', expected '%ls' but got '%ls'\n", tests[i].input, tests[i].expected, output.c_str()); } } + + // test for overflow + if (unescape_string(L"echo \\UFFFFFF", &output, UNESCAPE_DEFAULT)) + { + err(L"Should not have been able to unescape \\UFFFFFF\n"); + } + if (unescape_string(L"echo \\U110000", &output, UNESCAPE_DEFAULT)) + { + err(L"Should not have been able to unescape \\U110000\n"); + } + if (! unescape_string(L"echo \\U10FFFF", &output, UNESCAPE_DEFAULT)) + { + err(L"Should have been able to unescape \\U10FFFF\n"); + } + + } /**