trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
396 stars 78 forks source link

The parser get lost while parsing methods or call that has the pattern URL( #364

Closed alexcheveau closed 1 month ago

alexcheveau commented 1 year ago

Are you using the latest verion of NUglify, especially if used through BunderMinifier? Update before raising a bug as your issue is probably already fixed.

Describe the bug A clear and concise description of what the bug is.

To Reproduce Provide a minimal source code example AND how you are invoking NUglify

Minified output or stack trace Provide the minfied code which is erroneous or the stack trace in case of an exception

Excepted output code Provide the expected minified code

alexcheveau commented 1 year ago

This bug occurs with latest version (1.20.7) and also version 1.16.1 The parser get lost while parsing methods or call that has the pattern URL( Like return $h.objUrl.createObjectURL(data); Just try to parse https://github.com/kartik-v/bootstrap-fileinput/blob/master/js/fileinput.js return $h.objUrl.createObjectURL(data); becomes return $h.objUrl.createObjecturl(../data);

alexcheveau commented 1 year ago

Closed by mistake

trullock commented 1 year ago

You need to follow the ticket template and provide a minimum repro if you want me to help

alexcheveau commented 1 month ago

I'm using latest version NUglify-1.21.9

Describe the bug NUglify is parsing a specific pattern "URL(" wrongly messing the JS code

To Reproduce .NET 8

1-Startup.cs call: pipeline.AddJavaScriptBundle("/js/jqueryExtensions.js", ServiceHelper.GetCodeSettings(), "wwwroot/Scripts/jQuery/Extensions/DataTables/Buttons/*.js").UseContentRoot().AdjustRelativePaths().AddResponseHeaderCacheControl();

2-ServiceHelper.GetCodeSettings == return NUglify.JavaScript.CodeSettings.Pretty()

3-Just NUglify any JS with this specific pattern like https://cdn.datatables.net/buttons/3.1.2/js/buttons.html5.js

Minified output or stack trace Example 1 Original JS code: get_URL().revokeObjectURL(file); Result: get_URL().revokeObjecturl(../file);

Example 2 Original JS code: reader.readAsDataURL(blob); Result: reader.readAsDataurl(../blob);

alexcheveau commented 1 month ago

Reopen (template fulfilled)

alexcheveau commented 1 month ago
  1. The error occurs regardless off [MinifyCode=True/False]
  2. I'm using NUglify indirectly by AddWebOptimizer

Looking at the Project code, looks like this is a feature of CssParser (method ScanUrl) So why a CssParser is being used in a JS code?

alexcheveau commented 1 month ago

I created a simples console app to test calling directly NUglify with the file in question and the error does not occurs

var data = System.IO.File.ReadAllText(@"C:\\TEMP\\fileinput.js");
var x = NUglify.Uglify.Js(data, NUglify.JavaScript.CodeSettings.Pretty());
System.IO.File.WriteAllText("C:\\TEMP\\fileinput.js.nug", x.Code);

Input:

    createObjectURL: function (data) {
      if ($h.objUrl && $h.objUrl.createObjectURL && data) {
        return $h.objUrl.createObjectURL(data);
      }
      return "";
    },

NUglify.Pretty:

            createObjectURL: function(data)
            {
                if ($h.objUrl && $h.objUrl.createObjectURL && data)
                {
                    return $h.objUrl.createObjectURL(data)
                }
                return ""
            },

NUglify.Min:

        createObjectURL: function(n) {
            return t.objUrl && t.objUrl.createObjectURL && n ? t.objUrl.createObjectURL(n) : ""
        },

Generated by WebOptimizer:

    createObjectURL: function (data) {
      if ($h.objUrl && $h.objUrl.createObjectURL && data) {
        return $h.objUrl.createObjecturl(../data);
      }
      return "";
    },

So I think the problem is not related to NUglify itself Any help would be appreciated

alexcheveau commented 1 month ago

The error was totally mine I was using AdjustRelativePaths with JS files and this method if only for CSS