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



##########
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:
       @etr2460 I added some in `superset-ui` when I removed `mathjs` from the 
viz plugins: https://github.com/apache-superset/superset-ui/pull/1362. If you 
are able to pull in a set of real life test cases from you env I'd be happy to 
add some more complex test cases to the test suite 👍




-- 
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