1

I am trying to exclude all source map files, i.e files ending with .map from being uploaded to app engine. Here's a snippet of the config in app.yaml file.

handlers:
- url: /(.*\\..+(?\<!map))$
  static_files: \\1
  upload: /(.*\\..+(?\<!map))$
  secure: always

However, when deploying, this is the error that I get.

content <{
  "error": {
    "code": 400,
    "message": "The request is invalid.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "version.handlers[0].url_regex",
            "description": "Value \"/(.*\\..+(?\\\u003c!map))$\" must be a valid regular expression. Details: invalid or unsupported Perl syntax."
          },
          {
            "field": "version.handlers[0].static_files.upload_path_regex",
            "description": "Value \"/(.*\\..+(?\\\u003c!map))$\" must be a valid regular expression. Details: invalid or unsupported Perl syntax."
          }
        ]
      }

In the app.yaml reference documentation, it implies that it supports POSIX extended regular expression syntax.

Might anyone advice on what should be done to fix this.

Curtis
  • 63
  • 1
  • 5

1 Answers1

2

You can use

^(.*([^.].{3}|.[^m].{2}|.{2}[^a].|.{3}[^p])|.{0,3})$

See the regex demo. Details:

  • ^ - start of string
  • (.*([^.].{3}|.[^m].{2}|.{2}[^a].|.{3}[^p])|.{0,3}) - Group 1 matching:
    • .*([^.].{3}|.[^m].{2}|.{2}[^a].|.{3}[^p]) - any text, and then any of
      • [^.].{3}| - a char other than a . and then any 3 chars, or
      • .[^m].{2}| - any char, a char other than m, and then any two chars, or
      • .{2}[^a].| - any two chars, any char other than a, and then any one char
      • .{3}[^p] - any three chars, and then a char other than p
    • | - or
    • .{0,3} - any zero, one, two or three chars.
  • $ - end of string.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    Amazing. Many thanks. However, I've shortened it like so ```^(.*(.[^m].{2}|.{2}[^a].|.{3}[^p]))$``` . This seems to work too. –  Curtis Feb 18 '22 at 10:00
  • 1
    @Curtis Your `^(.*(.[^m].{2}|.{2}[^a].|.{3}[^p]))$` pattern won't find `a.a`, `.aa`, `.a`, `a` strings, that is probably fine in your case, but the pattern does not meet the "match any string not ending with `.map`" requirement set out in your question above. – Wiktor Stribiżew Feb 18 '22 at 10:04
  • I agree. And this is because I am tested this incorrectly. Many thanks for pointing it out. Useful links can be found here https://stackoverflow.com/questions/39636124/regular-expression-works-on-regex101-com-but-not-on-prod –  Curtis Feb 19 '22 at 13:43