angular icon indicating copy to clipboard operation
angular copied to clipboard

[BUG] Getting error while loading form using form-builder - unsafe-eval

Open vinayrdy966 opened this issue 1 year ago • 1 comments

  • Hosting type
    • [x] Form.io
    • [ ] Local deployment
      • Version:
  • Formio.js version: 4.19.4
  • Frontend framework: angular
  • Browser: all
  • Browser version: latest

Steps to Reproduce

  1. Just include this meta tag in index.html

angular template: <form-builder class="custom-form-builder" [form]="form" [options]="options"

image

vinayrdy966 avatar Jun 27 '24 14:06 vinayrdy966

If I replace this exiting code which is causing eval error in evaluator.js try { // Ensure we handle copied templates from the ejs files. _template = _template.replace(/ctx\./g, ''); return Evaluator.cache[hash] = _lodash["default"].template(_template, Evaluator.templateSettings); } catch (err) { console.warn('Error while processing template', err, _template); }

with this code I am able to resolve this issue. `try { _template = _template.replace(/ctx./g, ''); // Simple manual interpolation without using eval const context = { /* context values / }; _template = _template.replace(/{{\s([^{}\s])\s}}/g, (match, p1) => { return context[p1] || ''; });

Evaluator.cache[hash] = _template; return _template; } catch (err) { console.warn('Error while processing template', err, _template); }`

vinayrdy966 avatar Jul 02 '24 13:07 vinayrdy966

Thanks for the contribution!

lane-formio avatar Nov 19 '24 15:11 lane-formio