escaping malformed URI reference - html

I followed a youtube tutorial on webpack and got a linter error in my HTML stating:
escaping malformed URI reference
for this image tag:
<img class="img-responsive" src=<%=require('./images/tech-town-showcase-students.JPG') %> alt="students meeting with tech business owner"/>
What does "escaping" mean here? The code still seems to run just fine. What do I need to do differently to avoid the linter error?

Try wrapping your ASP embedded code in double quotations like this:
src="<%=require('./images/tech-town-showcase-students.JPG') %>"
Leaving them out causes me headaches to no end. It rarely breaks anything, but the html validators act as though you've tried to escape the tag you're embedding ASP in early by omitting the quotes. At least, in my experience.

Related

How to mute this error or disable the inspection in WebStorm or PhpStorm?

On Further Inspection (2019.10.07)
The problem is not limited to the error I originally saw. I think it stems from the fact that the IDE (or is it an Angular service?) is parsing and checking what's within <textarea> as if it were regular HTML whereas textarea content is really just raw text. The right approach might be to just consider everything inside <textarea> as a literal string.
Original Question
In PhpStorm, I am developing an Angular project. When in the template I use the open curly braces within a textarea like so:
<textarea>
{}
</textarea>
I get the error:
Unterminated expansion form. If you have unescaped '{', use '{{"{"}}' to escape it.
Assuming this { doesn't make the actual HTML invalid, I would like to mute this error or disable the inspection that generates it. Is that possible? If there is a way in WebStorm, it will probably also work in PhpStorm
This error can't be suppressed unfortunately.
Please vote for WEB-41745 to be notified on any progress with it

Valid HTML5 and img src-attribute on AngularJs ng-src

Anyone has idea, how to produce valid HTML5 when images are displayed with AngularJs ng-scr directive?
What I have discovered?
"src"- attribute is required on img-tags
It can't be empty
Console reports 404 error if I set src attribute data with angular binding, cause it tries to load image before Angular has initialized
Why I want valid HTML?
Reason is simple. Strange HTML errors (missing end tags, open tags etc..) causes strange behavior in our project where we have LOTS of views. Ensuring periodically that source is valid, makes code less unstable.
From this post stems a genious hack:
<img ng-src="modelImage" src="//:0">
...much easier to remember from the top of your head than an image URL ;)
ngSrc: any string which can contain {{}} markup.

ParseError: Unexpected end tag - How to clean html tags?

I'm starting to learn web development and am using pyramid with chameleon. I just took some sites html source as a template in Dreamweaver and then copied the code into a chameleon .pt file.
The html code displays fine in dreamweaver but I get this error when running it in pyramid:
chameleon.exc.ParseError
ParseError: Unexpected end tag.
- String: "</div>"
I have tried dreamweavers cleanup function and it said it removed 2 empty tags but I still get this error. My traceback is all related to errors in the chameleon and doesn't show the specific line its having problems with in my template itself.
Is there a way to identify the actual line where the error is occurring?
I'm not sure if there's a pyramid or chameleon specific solution or if there are general methods to find errors in HTML tag.
Chameleon expects templates to be well-formed, and is less forgiving of unbalanced tags and incorrect attribute markup as DreamWeaver is.
Note that the error doesn't necessarily mean that there is a </div> tag too many. If the opening <div> has a syntax error such as a missing = on an attribute declaration (e.g. <div class"foobar"> then the opening tag is not recognized and the corresponding closing tag is going to be flagged as well.
You could run your template through an XML validator, there are several available online (such as http://www.validome.org/xml/, http://www.xmlvalidation.com/ and http://xmlgrid.net/, Google lists many more). These are bound to give you a slightly more helpful message as to what is wrong with your template.
Never used pyramid/chameleon before, but it looks like you have to go through the code and remove an extra </div> tag. When you get the message that it removed two empty tags, that probably means it removed the open and closing of a set of tags
e.g. <div></div> or <p></p>
Go through your code and for every <div> there should be a </div>.

How to sanitize user generated html code in ruby on rails

I am storing user generated html code in the database, but some of the codes are broken (without end tags), so when this code will mess up the whole render of the page.
How could I prevent this sort of behaviour with ruby on rails.
Thanks
It's not too hard to do this with a proper HTML parser like Nokogiri which can perform clean-up as part of the processing method:
bad_html = '<div><p><strong>bad</p>'
puts Nokogiri.fragment(bad_html).to_s
# <div><p><strong>bad</strong></p></div>
Once parsed properly, you should have fully balanced tags.
My google-fu reveals surprisingly few hits, but here is the top one :)
Valid Well-formed HTML
Try using the h() escape function in your erb templates to sanitize. That should do the trick
Check out Loofah, an HTML sanitization library based on Nokogiri. This will also remove potentially unsafe HTML that could inject malicious script or embed objects on the page. You should also scrub out style blocks, which might mess up the markup on the page.

Perl AJAX stripping html characters out of string?

I have a Perl program that is reading html tags from a text file. (im pretty sure this is working because when i run the perl program on the command line it prints out the HTML like it should be.)
I then pass that "html" to the web page as the return to an ajax request. I then use innerHTML to stick that string into a div.
Heres the problem:
all the text information is getting to where it needs to be. but the "<" ">" and "/" are getting stripped.
any one know the answer to this?
The question is a bit unclear to me without some code and data examples, but if it is what it vaguely sounds like, you may need to HTML-encode your text (e.g. using HTML::Entities).
I'm kind of surprized that's an issue with inserting into innerHTML, but without specific example, that's the first thing which comes to mind
There could be a mod on the server that is removing special characters. Are you running Apache? (I doubt this is what's happening).
If something is being stripped on the client-side, it is most likely in the response handler portion of the AJAX call. Show your code where you stick the string in the div.