prokhor-ozornin / w3c-validator-net

.NET library to perform validation of CSS/(X)HTML documents, using WWW Consortium's (http://www.w3.org) web services.
https://www.nuget.org/packages/W3CValidator
GNU General Public License v3.0
1 stars 0 forks source link

Does not handle large CSS files #1

Open flakey-bit opened 6 years ago

flakey-bit commented 6 years ago

A file of 140Kb is sufficent to cause it to blow up (the issue is that the CSS is being added as a url-parameter "text" which blows out the URI length.

I've managed to work around the issue by invoking the API as a multipart/form-data POST (RFC2388 - see http://www.ietf.org/rfc/rfc2388.txt)

I used the FormUpload class here (also see this post) however RestSharp might be a better option.

code as follows:

            var userAgent = "";
            var cssBytes = Encoding.UTF8.GetBytes(css);
            var postParameters = new Dictionary<string, object>
            {
                {"output", "soap12"},
                {"file", new FormUpload.FileParameter(cssBytes, "uploadedfile.css", "text/css")}
            };

            ICssValidationResult validationResult;
            using (var response = FormUpload.MultipartFormDataPost("http://jigsaw.w3.org/css-validator/validator", userAgent, postParameters))
            {
                using (var stream = response.GetResponseStream())
                {
                    validationResult = GetValidationResult(stream);
                }
            }

            return validationResult;
prokhor-ozornin commented 5 years ago

As it turned out, SOAP interfaces for HTML/CSS validators are largely deprecated as of now, and the recommended approach is to use the following API: https://validator.w3.org/docs/api.html So it will take some time to rewrite associated library code for this new API.