Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions src/xinspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,12 @@ namespace xcpp
nl::json build_inspect_data(const std::string& inspect_result)
{
// Format html content.
std::string html_content = R"(<style>
#pager-container {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
.xcpp-iframe-pager {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
border: none;
}
</style>
<iframe class="xcpp-iframe-pager" src=")"
+ inspect_result + R"(?action=purge"></iframe>)";
// Note: cppreference.com sets X-Frame-Options: DENY, so an <iframe> is
// blocked by every browser. Use a plain link that opens in a new tab
// instead.
std::string html_content = R"(<a href=")" + inspect_result
+ R"(" target="_blank" rel="noopener noreferrer">)"
+ inspect_result + R"(</a>)";

auto data = nl::json::object({{"text/plain", inspect_result}, {"text/html", html_content}});
return data;
Expand Down
13 changes: 13 additions & 0 deletions test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,19 @@ TEST_SUITE("xinspect"){
cmp.child_value = "nonexistentMethod";
REQUIRE(cmp(node) == false);
}

TEST_CASE("build_inspect_data_link_not_iframe"){
// cppreference.com sets X-Frame-Options: DENY, so the output must use
// an <a> link instead of an <iframe>.
std::string url = "https://en.cppreference.com/w/cpp/container/vector";
nl::json data = xcpp::build_inspect_data(url);

REQUIRE(data.contains("text/html"));
std::string html = data["text/html"].get<std::string>();
REQUIRE(html.find("<iframe") == std::string::npos);
REQUIRE(html.find(url) != std::string::npos);
REQUIRE(html.find("<a href=") != std::string::npos);
}
}

#if !defined(__EMSCRIPTEN__)
Expand Down
Loading