Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up OdtDocument cursor position tests #783

Merged
merged 5 commits into from
Sep 23, 2014

Conversation

peitschie
Copy link
Contributor

Make OdtDocument cursor position tests more granular in how they are reported. This makes it easier to troubleshoot individual failing tests as the individual test is more specific.

  • Extend core test runner to cope with test names containing angle brackets
  • Verify the number of steps vs. expected number of cursor positions
  • Remove doc length check for non-changing variables
  • Report one test per cursor position document fragment

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2133/

@@ -569,7 +569,7 @@ core.UnitTester = function UnitTester() {
**/
function link(text, code) {
return "<span style='color:blue;cursor:pointer' onclick='" + code + "'>"
+ text + "</span>";
+ text.replace(/</g, "&lt;") + "</span>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to instead add a generic encodeForHTML (or better named) method which encodes <, > and & and to use it in all places where text is added to the HTML output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm. Where else are you proposing this encode function being used?

I actually would like to never see such a thing in production code, as the somewhat uncontrolled string concatenation happening here seems like very bad practice to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm. Where else are you proposing this encode function being used?

Now that I tried to list them, there might be only that one other place in core.UnitTester which I saw initially, https://github.com/kogmbh/WebODF/blob/master/webodf/lib/core/UnitTester.js#L635 Somehow I expected more :)

This also made me look at BrowserRuntime.log where I learned that any log messages which start with < are set to innerHTML (thus need to be encoded) while all others are just passed into a new text node, so do not need encoding, okay. So still leaves the encoding problem with those inBrowser-special logging with custom spans, where the caller has to make sure things are properly encoded.
And I also learned from e.g. http://shebang.brandonmintern.com/foolproof-html-escaping-in-javascript/ that encoding is best left to the browser, e.g. by

function escapeHtml(str) {
    var div = document.createElement('div');
    div.appendChild(document.createTextNode(str));
    return div.innerHTML;
};

Hm. So what to do here without going over-board. Just the proposed fix still seems to be too hacky and done on case-by-case.

Oh well. Without a better idea, please just add a comment to it that this is an unclean fix to a certain problem.

And while talking, in line 637 it should be test.description(), not test.description, or? Please give that a patch as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brandon and I share the same opinion about the best way to do escape.

I don't mind leaving this as a nasty hack for the simple reason that if it looks like a bad hack, no-one will be tempted to copy it out of the file 🎌. Or... if they do, it should become extremely obvious to the reviewer that this code was never meant to make it into production!

But, I will happily comment the line to reinforce this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still slightly confused why only < is cared for and not also > (and perhaps & for a possible test name char)? Because browsers can do proper error resolving with those other entities (no < before -> show < as char, no entity name after & -> show as char)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most browser display purposes, escaping the open-tag is sufficient to ensure the code isn't parsed as HTML. Escaping the ampersand isn't necessary with the test names I'm using so far, but it would make sense for future-proofing.

However, as discussed on the ML, I want to throw away all this code and replace it with jasmine anyway. As a result, I don't feel it's a good investment to do any real future-proofing on this part of the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh, okay. I would have made the escaping catch here a bit more broad given that examples show some non-[azAZ] chars to expect, but if you think this will soon be replaced and until then should just be hacked on case-by-case, well, there are more important things to discuss about :)
So please go with this and rebase and merge 🐹

@kossebau
Copy link
Contributor

For the rest looks good to me and more useful indeed.

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2147/

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2154/

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2155/

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2198/

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2245/

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2250/

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2255/

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/2266/

@peitschie
Copy link
Contributor Author

Thanks for reviewing!

peitschie added a commit that referenced this pull request Sep 23, 2014
Clean up OdtDocument cursor position tests
@peitschie peitschie merged commit f98e30c into webodf:master Sep 23, 2014
@peitschie peitschie deleted the test-improvements branch September 23, 2014 23:07
@kossebau kossebau mentioned this pull request Dec 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants