Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Update Suborigins grammar to match spec changes
Browse files Browse the repository at this point in the history
The spec took away semicolons from the grammar because they were
unnecessary. This CL updates the implementation and tests accordingly.

BUG=336894
[email protected]

Review-Url: https://codereview.chromium.org/2052033002
Cr-Commit-Position: refs/heads/master@{#399061}
  • Loading branch information
joelweinberger authored and Commit bot committed Jun 10, 2016
1 parent ff3dc65 commit 901620c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
header("Suborigin: foobar 'unsafe-postmessage-receive';");
header("Suborigin: foobar 'unsafe-postmessage-receive'");
?>
<!DOCTYPE html>
<html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

}

window.open("resources/post-document-to-parent.php?suborigin=foobar2&type=window&suboriginpolicy='unsafe-postmessage-send';");
window.open("resources/post-document-to-parent.php?suborigin=foobar2&type=window&suboriginpolicy='unsafe-postmessage-send'");
</script>
<iframe src="resources/post-document-to-parent.php?suborigin=foobar1&type=iframe&suboriginpolicy='unsafe-postmessage-send';"></iframe>
<iframe src="resources/post-document-to-parent.php?suborigin=foobar1&type=iframe&suboriginpolicy='unsafe-postmessage-send'"></iframe>
</html>
10 changes: 0 additions & 10 deletions third_party/WebKit/Source/platform/network/HTTPParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,16 +740,6 @@ bool parseSuboriginHeader(const String& header, Suborigin* suborigin, WTF::Vecto
messages.append("Ignoring unknown suborigin policy option " + optionName + ".");
else
suborigin->addPolicyOption(option);

skipWhile<UChar, isASCIISpace>(position, end);
if (position == end || *position != ';') {
String found = (position == end) ? "end of string" : String(position, 1);
messages.append("Invalid suborigin policy Expected ';' at end of policy option. Found \'" + found + "\' instead.");
suborigin->clear();
return false;
}

position++;
}

return true;
Expand Down
26 changes: 13 additions & 13 deletions third_party/WebKit/Source/platform/network/HTTPParsersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,25 @@ TEST(HTTPParsersTest, SuboriginParseValidPolicy)
const Suborigin::SuboriginPolicyOptions unsafePostmessageSendAndReceive[] = { Suborigin::SuboriginPolicyOptions::UnsafePostMessageSend, Suborigin::SuboriginPolicyOptions::UnsafePostMessageReceive };

// All simple, valid policies
expectParsePolicyPass("One policy, unsafe-postmessage-send", "foobar 'unsafe-postmessage-send';", unsafePostmessageSend, ARRAY_SIZE(unsafePostmessageSend));
expectParsePolicyPass("One policy, unsafe-postmessage-receive", "foobar 'unsafe-postmessage-receive';", unsafePostmessageReceive, ARRAY_SIZE(unsafePostmessageReceive));
expectParsePolicyPass("One policy, unsafe-postmessage-send", "foobar 'unsafe-postmessage-send'", unsafePostmessageSend, ARRAY_SIZE(unsafePostmessageSend));
expectParsePolicyPass("One policy, unsafe-postmessage-receive", "foobar 'unsafe-postmessage-receive'", unsafePostmessageReceive, ARRAY_SIZE(unsafePostmessageReceive));

// Formatting differences of policies and multiple policies
expectParsePolicyPass("One policy, whitespace all around", "foobar 'unsafe-postmessage-send' ; ", unsafePostmessageSend, ARRAY_SIZE(unsafePostmessageSend));
expectParsePolicyPass("Multiple, same policies", "foobar 'unsafe-postmessage-send'; 'unsafe-postmessage-send';", unsafePostmessageSend, ARRAY_SIZE(unsafePostmessageSend));
expectParsePolicyPass("Multiple, different policies", "foobar 'unsafe-postmessage-send'; 'unsafe-postmessage-receive';", unsafePostmessageSendAndReceive, ARRAY_SIZE(unsafePostmessageSendAndReceive));
expectParsePolicyPass("One policy, unknown option", "foobar 'unknown-option';", {}, 0);
expectParsePolicyPass("One policy, whitespace all around", "foobar 'unsafe-postmessage-send' ", unsafePostmessageSend, ARRAY_SIZE(unsafePostmessageSend));
expectParsePolicyPass("Multiple, same policies", "foobar 'unsafe-postmessage-send' 'unsafe-postmessage-send'", unsafePostmessageSend, ARRAY_SIZE(unsafePostmessageSend));
expectParsePolicyPass("Multiple, different policies", "foobar 'unsafe-postmessage-send' 'unsafe-postmessage-receive'", unsafePostmessageSendAndReceive, ARRAY_SIZE(unsafePostmessageSendAndReceive));
expectParsePolicyPass("One policy, unknown option", "foobar 'unknown-option'", {}, 0);
}

TEST(HTTPParsersTest, SuboriginParseInvalidPolicy)
{
expectParsePolicyFail("One policy, no suborigin name", "'unsafe-postmessage-send';");
expectParsePolicyFail("One policy, invalid characters", "foobar 'un$afe-postmessage-send';");
expectParsePolicyFail("One policy, caps", "foobar 'UNSAFE-POSTMESSAGE-SEND';");
expectParsePolicyFail("One policy, missing first quote", "foobar unsafe-postmessage-send';");
expectParsePolicyFail("One policy, missing last quote", "foobar 'unsafe-postmessage-send;");
expectParsePolicyFail("One policy, missing semicolon at end", "foobar 'unsafe-postmessage-send'");
expectParsePolicyFail("Multiple policies, missing semicolon between options", "foobar 'unsafe-postmessage-send' 'unsafe-postmessage-send';");
expectParsePolicyFail("One policy, no suborigin name", "'unsafe-postmessage-send'");
expectParsePolicyFail("One policy, invalid characters", "foobar 'un$afe-postmessage-send'");
expectParsePolicyFail("One policy, caps", "foobar 'UNSAFE-POSTMESSAGE-SEND'");
expectParsePolicyFail("One policy, missing first quote", "foobar unsafe-postmessage-send'");
expectParsePolicyFail("One policy, missing last quote", "foobar 'unsafe-postmessage-send");
expectParsePolicyFail("One policy, invalid character at end", "foobar 'unsafe-postmessage-send';");
expectParsePolicyFail("Multiple policies, extra character between options", "foobar 'unsafe-postmessage-send' ; 'unsafe-postmessage-send'");
}

} // namespace blink

0 comments on commit 901620c

Please sign in to comment.