Repository: Shopify/shopify-cli (Ruby)

Issue:
Shopify Theme Asset URL not handling whitespace clearers correctly
# Issue summary
When running a `shopify theme serve` command, the CLIis currently replacing `{{ '...' | asset_url }}` with a reference to the local server (127.0.0.1:9292), however when using the whitespace clearers, e.g. `{{- '...' | asset_url -}}` the URL is still pointing back to Shopify's CDN.

As a result, local changes are not reflected immediately due to Shopify's CDN Caching.


## Expected behavior
Regardless of  `{{-` or `{{` the URL should be rewritten correctly.

## Actual behavior
`{{- 'theme.css' | asset_url | stylesheet_tag -}}` refers to the Shopify CDN URL.


## Steps to reproduce the problem

1. Load a new theme using `shopify theme serve`
2. Add a `theme.css` file with some declarations like `* { background: red !important; }`
3. Add `{{- 'theme.css' | asset_url | stylesheet_tag -}}` to your `layout.liquid` file
4. Inspect the URL on the preview `127.0.0.1:9292` webpage, notice the CDN url `//cdn.shopify.com/.../theme.css?v=...` rather than `http://127.0.0.1:9292/theme.css`



## Specifications

- App type: theme
- Operating System: Windows 10
- Shell: PowerShell
- Ruby version (ruby -v): Ruby 2.7.2, Shopify CLI v2.3.0



Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 758e6ae2ea..f260e18be4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
 From version 2.6.0, the sections in this file adhere to the [keep a changelog](https://keepachangelog.com/en/1.0.0/) specification.
 ## [Unreleased]
+### Fixed
+* [#1714](https://github.com/Shopify/shopify-cli/pull/1714): Fix theme serve not serving assets locally when two URLs are on the same line
 
 ## Version 2.6.6
 ### Added
diff --git a/lib/shopify_cli/theme/dev_server/local_assets.rb b/lib/shopify_cli/theme/dev_server/local_assets.rb
index 709e848ffd..d2640eb0eb 100644
--- a/lib/shopify_cli/theme/dev_server/local_assets.rb
+++ b/lib/shopify_cli/theme/dev_server/local_assets.rb
@@ -4,7 +4,7 @@ module ShopifyCLI
   module Theme
     module DevServer
       class LocalAssets
-        ASSET_REGEX = %r{//cdn.shopify.com/s/.*?/(assets/.+\.(?:css|js))}
+        ASSET_REGEX = %r{//cdn\.shopify\.com/s/.+?/(assets/.+?\.(?:css|js))}
 
         class FileBody
           def initialize(path)


Test patch:
diff --git a/test/shopify-cli/theme/dev_server/local_assets_test.rb b/test/shopify-cli/theme/dev_server/local_assets_test.rb
index 3898311a5a..ed56d4463c 100644
--- a/test/shopify-cli/theme/dev_server/local_assets_test.rb
+++ b/test/shopify-cli/theme/dev_server/local_assets_test.rb
@@ -25,6 +25,24 @@ def test_replace_local_assets_in_reponse_body
           assert_equal(expected_html, serve(original_html).body)
         end
 
+        def test_replace_local_assets_on_same_line
+          original_html = <<~HTML
+            <html>
+              <head>
+                <link rel="stylesheet" href="//cdn.shopify.com/s/files/1/0457/3256/0918/t/2/assets/theme.css?enable_css_minification=1&v=3271603065762738033" /><link rel="stylesheet" href="//cdn.shopify.com/s/files/1/0457/3256/0918/t/2/assets/theme.css?enable_css_minification=1&v=3271603065762738033" />
+              </head>
+            </html>
+          HTML
+          expected_html = <<~HTML
+            <html>
+              <head>
+                <link rel="stylesheet" href="/assets/theme.css?enable_css_minification=1&v=3271603065762738033" /><link rel="stylesheet" href="/assets/theme.css?enable_css_minification=1&v=3271603065762738033" />
+              </head>
+            </html>
+          HTML
+          assert_equal(expected_html, serve(original_html).body)
+        end
+
         def test_dont_replace_other_assets
           original_html = <<~HTML
             <html>