ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
780 stars 114 forks source link

Double @ in <script src=""> causes unexpected bug #161

Open jasonkuo41 opened 3 years ago

jasonkuo41 commented 3 years ago

Description

When using razor pages, if the script tag contains @@, using the provided tag helper (@addTagHelper *, WebOptimizer.Core) would mess up the code.

Example

<script src="https://unpkg.com/@@barba/core"></script>

Due to @ is a special character in Razor Pages, we need @@ to escape it being interpreted the wrong way.

Expect Output

Excepted in final HTML render:

<script src="https://unpkg.com/@barba/core"></script>

Actual Output

Output in final HTML render:

<script src=" href=" https:="" unpkg.com="" @="" href="barba/core"></script>

Workaround

Force to use @() directly

<script src="@("https://unpkg.com/@barba/core")"></script>
lesh-andrew commented 1 month ago

I ran into this today while setting up VS on a new computer and was testing out WebOptimizer for the first time. I found the following works as well and is cleaner if you already have a code section in your page/view; just posting in case anybody finds it useful.

@{
.
.
.
   // other lines of code
    var popperURL = "https://unpkg.com/@popperjs/core@2";
}

<script src="@popperURL"></script>