ParserFunctions: Fail if `e0` or `pi0` [#819]

master
gnosygnu 4 years ago
parent b1c52aa2b2
commit 7d357540c7

@ -113,6 +113,7 @@ public class Pfunc_expr_shunter {
if (cur_prc.Func_is_const()) { // func is "pi" or "e"; DATE:2014-03-01
if (mode_expr) { // number expected; just call Calc (which will place value on stack)
cur_prc.Calc(ctx, this, val_stack);
mode_expr = false; // 2020-11-25|ISSUE#:819|Set mode_expr to false which forces next term to be operator not number. EX: `pi0` -> fails
break;
}
else // operator expected; fail b/c pi / e is not an operator;
@ -121,6 +122,9 @@ public class Pfunc_expr_shunter {
if (mode_expr) { // NOTE: all the GetAlts have higher precedence; "break;" need to skip evaluation below else will fail for --1
Func_tkn alt_prc = cur_prc.GetAlt();
prc_stack.Push(alt_prc);
if (alt_prc == Func_tkn_e_const.Instance) {
mode_expr = false; // 2020-11-25|ISSUE#:819|Set mode_expr to false which forces next term to be operator not number. EX: `e0` -> fails
}
break;
}
prv_prc = prc_stack.Get_at_last();

@ -115,4 +115,10 @@ public class Pfunc_expr_tst {
@Test public void Num_precision() {// PURPOSE: number should be set to precision of 14; PAGE:de.wikipedia.org/wiki/Nationalpark_Mu_Ko_Ang_Thong ISSUE#:683 DATE:2020-03-24
fxt.Test__parse__tmpl_to_html("{{#expr:15.064329981401556}}", "15.064329981402"); // fails if 15.06432998140155
}
@Test public void Const_e_suffix_should_fail() { // 2020-11-25|ISSUE#:819|Do not interpret 'e0' as 'e'; EX: e0 x> 2.71828
fxt.Test_parse_page_tmpl_str("{{#expr:e0}}", "<strong class=\"error\">Expression error: Unexpected number</strong>");
}
@Test public void Const_pi_suffix_should_fail() { // 2020-11-25|ISSUE#:819|Do not interpret 'pi0' as 'pi'; EX: e0 x> 3.141529
fxt.Test_parse_page_tmpl_str("{{#expr:pi0}}", "<strong class=\"error\">Expression error: Unexpected number</strong>");
}
}

Loading…
Cancel
Save