From 90b938489916060859702ad4f5eecb96deb9730f Mon Sep 17 00:00:00 2001 From: Jeremy Studer Date: Thu, 22 Mar 2018 23:34:22 -0400 Subject: [PATCH] Panic when given empty character class <[]> Check whether the QAST node has any children to determine if it is empty. The exception are the backslash cclass nodes (\b, \n, \s, etc). --- src/QRegex/P6Regex/Actions.nqp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/QRegex/P6Regex/Actions.nqp b/src/QRegex/P6Regex/Actions.nqp index b5f3d3d0f4..cee2db9f1f 100644 --- a/src/QRegex/P6Regex/Actions.nqp +++ b/src/QRegex/P6Regex/Actions.nqp @@ -772,6 +772,13 @@ class QRegex::P6Regex::Actions is HLL::Actions { QAST::Regex.new( :rxtype, :name<.> ) ) !! QAST::Regex.new( :rxtype, |@alts ); } + + if $qast.rxtype ne 'cclass' && +@($qast) == 0 { + $/.panic('Cannot have an empty character class. If you intended to include ' + ~ 'whitespace within this character class, escape it with \\' + ); + } + make $qast; }