Variable file() path isn't parsed if it contains `@`
See original GitHub issueThis is a Bug Report
Description
I’m trying to load variables from a scoped npm module in serverless.yml
:
custom:
variableFromFile: ${file(node_modules/@scope/module-name/variables.json):variableName}
But when I try to deploy the service, I get the following error:
TypeError: Cannot read property 'Policies' of undefined
at functionObj.events.forEach.event (/Users/adam/.config/yarn/global/node_modules/serverless/lib/plugins/aws/package/compile/events/stream/index.js:182:18)
at Array.forEach (<anonymous>)
at serverless.service.getAllFunctions.forEach (/Users/adam/.config/yarn/global/node_modules/serverless/lib/plugins/aws/package/compile/events/stream/index.js:41:28)
at Array.forEach (<anonymous>)
at AwsCompileStreamEvents.compileStreamEvents (/Users/adam/.config/yarn/global/node_modules/serverless/lib/plugins/aws/package/compile/events/stream/index.js:16:47)
at BbPromise.reduce (/Users/adam/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:55)
From previous event:
at PluginManager.invoke (/Users/adam/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:22)
at PluginManager.spawn (/Users/adam/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:384:17)
at Deploy.BbPromise.bind.then.then (/Users/adam/.config/yarn/global/node_modules/serverless/lib/plugins/deploy/deploy.js:120:50)
From previous event:
at Object.before:deploy:deploy [as hook] (/Users/adam/.config/yarn/global/node_modules/serverless/lib/plugins/deploy/deploy.js:110:10)
at BbPromise.reduce (/Users/adam/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:55)
From previous event:
at PluginManager.invoke (/Users/adam/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:22)
at PluginManager.run (/Users/adam/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:397:17)
at variables.populateService.then (/Users/adam/.config/yarn/global/node_modules/serverless/lib/Serverless.js:104:33)
at runCallback (timers.js:785:20)
at tryOnImmediate (timers.js:747:5)
at processImmediate [as _immediateCallback] (timers.js:718:5)
From previous event:
at Serverless.run (/Users/adam/.config/yarn/global/node_modules/serverless/lib/Serverless.js:91:74)
at serverless.init.then (/Users/adam/.config/yarn/global/node_modules/serverless/bin/serverless:42:50)
at <anonymous>
If I copy the JSON file to a path that doesn’t contain the @
symbol, it works.
Additional Data
- Serverless Framework Version you’re using: 1.24.1
- Operating System: OSX
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Parse directory path to a variable in python - Stack Overflow
It could be because I'm on OSX and that isn't recognized as a file path. Regardless, this solution is a bit simpler and...
Read more >parse_ini_file - Manual - PHP
The filename of the ini file being parsed. If a relative path is used, it is evaluated relative to the current working directory,...
Read more >GNU make
GNU make. This file documents the GNU make utility, which determines automatically which pieces of a large program need to be recompiled, ...
Read more >include - Apache FreeMarker Manual
The included file shares the variables with the including template, similarly like if it was copy-pasted into it. The include directive is ......
Read more >Path Class (System.IO) - Microsoft Learn
Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We should rather go for a blacklist regex here:
/^file\(([^?%*:|"<>]+?)\)/
I’m not sure why the file syntax does not even allow for absolute paths. Imo we should allow these. The regex I wrote above seems to be suitable. It allows for any valid filename.
The reason for this bug is quite simple. The regex we use to parse the file variable syntax just does not allow for
@
./^file\((~?[a-zA-Z0-9._\-/]+?)\)/
So only alphanumeric characters are allowed including slashes, underscores and dashes. BTW: Using Windows path separators will also break 🤔
We should instead use a regex that really matches file paths (including
\
and some special characters.