Repository: serverless/serverless (JavaScript) — Bug Fix

Issue:
Error in regular expression that checks S3 URLs
<!--
1. If you have a question and not a bug report please ask first at http://forum.serverless.com
2. Please check if an issue already exists. This bug may have already been documented
3. Check out and follow our Guidelines: https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md
4. Fill out the whole template so we have a good overview on the issue
5. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
6. Please follow the template, otherwise we'll have to ask you to update it
-->

# This is a Bug Report

## Description

- What went wrong?

In `lib/plugins/aws/package/compile/functions/index.js`, the regular expression to match `s3.amazonaws.com` does not escape the `.` characters, so they match any single character rather than only `.`.

- What did you expect should have happened?

I expected a typo like `s33amazonaws.com` to not be routed to the S3 logic. (This was only done in tests though. I did not run into this issue while actually using the software.)

- What was the config you used?

N/A

- What stacktrace or error message from your provider did you see?

N/A

Similar or dependent issues:


## Additional Data

- **_Serverless Framework Version you're using_**: master branch
- **_Operating System_**: macOS Mojave
- **_Stack Trace_**: N/A
- **_Provider Error messages_**: N/A



Discussion:

Resolving patch:
diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js
index 004cf14c936..ee38dc221ae 100644
--- a/lib/plugins/aws/package/compile/functions/index.js
+++ b/lib/plugins/aws/package/compile/functions/index.js
@@ -83,7 +83,7 @@ class AwsCompileFunctions {
       _.get(functionObject, 'package.artifact') ||
       _.get(this, 'serverless.service.package.artifact');
 
-    const regex = new RegExp('.*s3.amazonaws.com/(.+)/(.+)');
+    const regex = new RegExp('s3\\.amazonaws\\.com/(.+)/(.+)');
     const match = artifactFilePath.match(regex);
 
     if (match) {


Test patch:
diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js
index bd533359344..dee42115ae5 100644
--- a/lib/plugins/aws/package/compile/functions/index.test.js
+++ b/lib/plugins/aws/package/compile/functions/index.test.js
@@ -140,6 +140,20 @@ describe('AwsCompileFunctions', () => {
         expect(artifactFileName).to.equal(s3ArtifactName);
       });
     });
+
+    it('should not access AWS.S3 if URL is not an S3 URl', () => {
+      AWS.S3.restore();
+      const myRequestStub = sinon.stub(AWS, 'S3').returns({
+        getObject: () => {
+          throw new Error('should not be invoked');
+        },
+      });
+      awsCompileFunctions.serverless.service.functions[functionName].package.artifact =
+        'https://s33amazonaws.com/this/that';
+      return expect(awsCompileFunctions.downloadPackageArtifacts()).to.be.fulfilled.then(() => {
+        expect(myRequestStub.callCount).to.equal(1);
+      });
+    });
   });
 
   describe('#compileFunctions()', () => {