etr2460 commented on a change in pull request #16701:
URL: https://github.com/apache/superset/pull/16701#discussion_r711170213



##########
File path: 
superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.jsx
##########
@@ -204,15 +204,30 @@ export default class AnnotationLayer extends 
React.PureComponent {
     return sources;
   }
 
-  isValidFormula(value, annotationType) {
+  isValidFormula(expression, annotationType) {
     if (annotationType === ANNOTATION_TYPES.FORMULA) {
       try {
-        mathjsParse(value).compile().evaluate({ x: 0 });
+        const token = {
+          type: 3,
+          token: 'x',
+          show: 'x',
+          value: 'x',
+        };
+
+        // handle input like "y = x+1" instead of just "x+1"
+        const subexpressions = expression.split('=');
+        if (
+          subexpressions.length > 2 ||
+          (subexpressions[1] && !subexpressions[0].match(/^[a-zA-Z]\w*$/))
+        ) {
+          return false;
+        }
+        mexp.eval(subexpressions[1] ?? subexpressions[0], [token], { x: 0 });

Review comment:
       do we have unit tests for this change? while i agree it's good to 
replace mathjs, i would appreciate it if we:
   - pulled some real life annotation formula values from the database (if you 
need examples, i can provide some)
   - wrote unit tests based off those
   - ensure they still pass after changing the dev




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to