not-node 6.3.49 → 6.3.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/form/form.js +31 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.3.49",
3
+ "version": "6.3.50",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/form/form.js CHANGED
@@ -1,3 +1,4 @@
1
+ const Schema = require("mongoose").Schema;
1
2
  const validator = require("validator");
2
3
  const notPath = require("not-path");
3
4
  const FormFabric = require("./fabric");
@@ -588,6 +589,23 @@ class Form {
588
589
  };
589
590
  }
590
591
 
592
+ /**
593
+ *
594
+ * @param {Object} schemaField
595
+ */
596
+ extractDefaultTransformers(schemaField) {
597
+ if (typeof schemaField === "undefined" || schemaField === null) {
598
+ return [];
599
+ }
600
+ switch (schemaField.type) {
601
+ case String:
602
+ case Schema.Types.String:
603
+ return ["xss"];
604
+ default:
605
+ return [];
606
+ }
607
+ }
608
+
591
609
  /**
592
610
  *
593
611
  * @param {import('../types.js').notNodeExpressRequest} req
@@ -597,7 +615,7 @@ class Form {
597
615
  */
598
616
  createInstructionFromRouteActionFields(
599
617
  req,
600
- mainInstruction = ["fromBody", "xss"],
618
+ mainInstruction = ["fromBody"],
601
619
  exceptions = {}
602
620
  ) {
603
621
  const result = {};
@@ -614,7 +632,17 @@ class Form {
614
632
  if (objHas(exceptions, fieldName)) {
615
633
  result[fieldName] = exceptions[fieldName];
616
634
  } else {
617
- result[fieldName] = mainInstruction;
635
+ const fieldTransformers = this.extractDefaultTransformers(
636
+ schema[fieldName]
637
+ );
638
+ if (Array.isArray(fieldTransformers)) {
639
+ result[fieldName] = [
640
+ ...mainInstruction,
641
+ ...fieldTransformers,
642
+ ];
643
+ } else {
644
+ result[fieldName] = [...mainInstruction];
645
+ }
618
646
  }
619
647
  });
620
648
  // @ts-ignore
@@ -631,7 +659,7 @@ class Form {
631
659
  */
632
660
  extractByInstructionsFromRouteActionFields(
633
661
  req,
634
- mainInstruction = ["fromBody", "xss"],
662
+ mainInstruction = ["fromBody"],
635
663
  exceptions = {},
636
664
  additional = {}
637
665
  ) {