@bedrockio/templates 0.3.0 → 0.3.2

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.3.2
2
+
3
+ - Fixed oddness with SWC's handling of Function#toString.
4
+
5
+ ## 0.3.1
6
+
7
+ - Fixed issue with long filenames.
8
+
1
9
  ## 0.3.0
2
10
 
3
11
  - Allow getting template source.
@@ -128,7 +128,7 @@ function resolveHelper(arg, options) {
128
128
  };
129
129
  }
130
130
  // Arguments
131
- const ARGUMENT_NAMES_REG = /\w+\((.+)\) {/;
131
+ const ARGUMENT_NAMES_REG = /\w+\s?\((.+)\) {/;
132
132
  function resolveArgumentNames(arg) {
133
133
  if (typeof arg === 'function') {
134
134
  const handler = arg;
package/dist/cjs/utils.js CHANGED
@@ -13,7 +13,7 @@ const front_matter_1 = __importDefault(require("front-matter"));
13
13
  function resolveTemplateSource(arg, options) {
14
14
  const { dir } = options;
15
15
  let source;
16
- if (dir) {
16
+ if (dir && isValidFilename(arg)) {
17
17
  const filepath = path_1.default.resolve(dir, arg);
18
18
  source = readSource(filepath) || arg;
19
19
  }
@@ -47,6 +47,9 @@ function readSource(filepath) {
47
47
  return tryReadFile(filepath + '.md') || tryReadFile(filepath + '.txt');
48
48
  }
49
49
  }
50
+ function isValidFilename(str) {
51
+ return str.length <= 255 && !str.includes('\n');
52
+ }
50
53
  // Sections
51
54
  const SECTIONS_REG = /^=== (\w+) ===\n\n/gm;
52
55
  function getSections(str) {
@@ -121,7 +121,7 @@ function resolveHelper(arg, options) {
121
121
  };
122
122
  }
123
123
  // Arguments
124
- const ARGUMENT_NAMES_REG = /\w+\((.+)\) {/;
124
+ const ARGUMENT_NAMES_REG = /\w+\s?\((.+)\) {/;
125
125
  function resolveArgumentNames(arg) {
126
126
  if (typeof arg === 'function') {
127
127
  const handler = arg;
package/dist/esm/utils.js CHANGED
@@ -4,7 +4,7 @@ import frontmatter from 'front-matter';
4
4
  export function resolveTemplateSource(arg, options) {
5
5
  const { dir } = options;
6
6
  let source;
7
- if (dir) {
7
+ if (dir && isValidFilename(arg)) {
8
8
  const filepath = path.resolve(dir, arg);
9
9
  source = readSource(filepath) || arg;
10
10
  }
@@ -38,6 +38,9 @@ function readSource(filepath) {
38
38
  return tryReadFile(filepath + '.md') || tryReadFile(filepath + '.txt');
39
39
  }
40
40
  }
41
+ function isValidFilename(str) {
42
+ return str.length <= 255 && !str.includes('\n');
43
+ }
41
44
  // Sections
42
45
  const SECTIONS_REG = /^=== (\w+) ===\n\n/gm;
43
46
  export function getSections(str) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/templates",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Bedrock utility for custom templates.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAKA,mEAYC;AAED;;;EAOC;AAwBD;;;;;IAsBC;AAMD,6CAMC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAKA,mEAYC;AAED;;;EAOC;AA4BD;;;;;IAsBC;AAMD,6CAMC"}