CakePHP 3: Prevent partially rendered view from appearing when error is rendered - cakephp-3.0

In /Template/Error/ I modified error400.ctp and eror500.ctp to use the default layout when debugging is switched off.
This works fine. But if an error does not occur in the code of the controller's action, but in the view (e.g. due to queries that are executed only as soon as needed in the view), then the error page contains the part of the original action's view that was rendered, and then the html code of the layout and contents for displaying the error:
<form method="post" accept-charset="utf-8" action="/index">
<div class="box-normal">
<select>…</select>
<!-- the error occurs after the next </div>,
and after that the output of the error page
starts with <!DOCTYPE html> -->
</div><!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This is of course invalid html, and also confusing for the user.
Is there any way to flush the output buffer before the error is rendered so that any parts of views that were already rendered are discarded?

Related

Handlebars.net not preserving white space

I have the following template:
<!DOCTYPE html>
<html>
<body>
{{>Header}}
This is a test template.
{{>Footer}}
</body>
</html>
When I compile this template, I'd expect to get this:
<!DOCTYPE html>
<html>
<body>
This is a header.
This is a test template.
This is a footer.
</body>
</html>
Instead, what I get is this:
<!DOCTYPE html>
<html>
<body>
This is a header. This is a test template.
This is a footer.</body>
</html>
The indentations before the first and third lines are gone; and the newlines before the second line and closing body tag are gone. Is this expected, and is there a way to preserve the whitespace just as it is laid out in the base template? I should note that I'm using Handlebars.Net here, although my understanding is that it's meant to emulate the original Javascript spec as closely as possible.
(Answer from the Github issue where this was also posted):
So there's two different things going on here that I'll summarize first and then explain: 1) what you expect is incorrect; 2) what you are getting is also incorrect, in a different way:
Whitespace (and line breaks) are not significant in HTML, and though Handlebars is technically a general string templating language, the design decisions & opinions it contains are heavily slanted towards using it for an HTML templating language. You should not expect it to preserve implicit line breaks, only explicit line breaks (e.g. if you put \n it will preserve that)
Handlebars.Net actually DOES preserve some line breaks when it's not supposed to! That's a bug but one many users are currently relying on, so we'll keep it in 1.x but fix it in v2.
To get your desired output, put explicit line breaks in your template. Cheers!

Need w3-include-html partial include

I´m using this W3 script:
<!DOCTYPE html>
<html>
<script src="https://www.w3schools.com/lib/w3.js"></script>
<body>
<div w3-include-html="content.html"></div>
<script>
w3.includeHTML();
</script>
</body>
</html>
It works perfectly, but my issue would be that I only need one particular portion of the "content.html", and not all of it. So my question is: How do I use w3-include-html for PARTIALLY html include?
Thanks!!
You can't include part of a partial; the whole point of a 'partial' is that it in itself represents part of the code, not code that you should extract a part from.
You can include more than one partial on a page, but the partials themselves must be exactly what you're trying to include at that point; you can't 'extract' content from a partial.
Simply shrink your content.html so that it only contains the output that you would like to include on your main page.
Having said that, considering W3.js can only import HTML, there's literally no reason to store the partial HTML in an external file. Not only does this create a second, unecessary file, but it also adds a reliance on JavaScript. If your visitor opts to disable their JavaScript, your partial won't work. Thus, I strongly recommend simply writing the content of content.html in the main page itself.
Hope this helps!

Error Message saying XML is invalid on SharePoint master page

I am branding SharePoint and when I upload the master page I get an error that says
The 'html' start tag on line 162 position 2 does not match the end tag
of 'head'. Line 171, position 3.
So I check my html file and I can't seem to find what's wrong. Here is the html: https://codeshare.io/GbvxJV
I have reviewed your XML file and find out below bugs:
You need to add <html> tag below <!DOCTYPE html> tag.
The second change is, you need to complete your <head> tag (before <body> tag starts) at line number 162, as suggested in error as well.
There are lots of <SPM> tag that are spit in multiple lines. They need to be in single line.
When I make these changes, I was able to convert your HTML file to Master Page.

Find text content in QWebView Failed

In my Qt project, I want to find the text content in QWebView. I have tried the QWebElement method, but it failed.
My html is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>nothing</title>
<style>
input[type=text] { font-size:15px; width:200; background:#ccc}
</style>
</head>
<p> hello </p>
<body>
<input type='text' name='hello' value='good luck'/>
</body>
</html>
Now, I want to edit this html, for example, I want the text display "hello, qt". And my code is:
QWebView * webView = new QWebView();
webView->load(QUrl::fromLocalFile("C:\\Users\\zhq\\Desktop\\QT_VTK_MIP\\qt.html"));
QWebElement document = webView->page()->currentFrame()->documentElement();
QWebElement firstTextInput = document.findFirst("input[type=text]");
QString storedText = firstTextInput.attribute("value");
firstTextInput.setAttribute("value",QString("hello,qt"));
webView->show();
However, the html can be display normally by QWebView, but the text content has not been modified as "hello, qt".
After debugging the code, I find the findFirst function return a NULL value. So, what's wrong with the findFirst function.
And, what if several text exist in the html? How can I using the name of the text to identify what I actually need?
Any suggestion means a lot for me. Thanks in advance.
ZhQ
Firstly, I want to say that the code is ok. Of course, the result really make me confused.
The reason that make the code didn't work is that "QWebView use asynchrone component, so the web page loading is make throw eventloop execution." Which means the qwebview didn't actually load the html after the qwebview::load function.
First of all, the html is shown normally in the qwidget. And I add a button in the qwidget. When I click the button, I change the text content in the slot function, and it worked.
zhq

Ignoring base tag after post

On Chrome I'm getting an error Refused to execute a JavaScript script. Source code of script found within request. after posting data that contains the name of the domain (also note the lack of javascript on either page) .
badpage1.html:
<form action="/badpage2.html" method="post">
<input type="hidden" name="name" value="href=%22http://www.w3.org/%22"/>
<input type="submit" name="submit"/>
</form>
badpage2.html:
<!DOCTYPE html>
<html>
<head>
<base href="http://www.w3.org/"/>
</head>
<body>
<img src="Icons/w3c_home" alt="">
</body>
</html>
If you go directly to badpage2.html the image will show, but if you go to it via badpage1.html, the image will not show (base tag doesn't work).
Is this a bug in Chrome XSS detection? And if it's not, how would I bypass this? It seems silly to encode the posted data just to bypass this filter.
EDIT:
In my case, the post value sent is to update part of the content of the page. The problem comes if it contains happens to contain the domain name that is used in the <base> (as this example does) it will trigger the XSS detection which disables the <base> tag.
I found out that I can send the custom HTTP header X-XSS-Protection on the page that is being messed up due to the protection.
I use the below code for my PHP solution:
header( "X-XSS-Protection: 0" );