Skip to content

Syntax highlighting can break if a quote-mark is used within "synthetic" #4

@manarth

Description

@manarth

In vcl_error, we use synthetic to deliver an error response.

Within that response, there are quote-marks. The syntax-highlighter is interpreting these as the end of the synthetic response, when they're actually part of the output.

Within a synthetic response, the scope of the output begins with {" and ends with "}. A quote mark on its own, without the closing curly-bracket, is part of the content.

Here's the code we're using:

# In the event of an error, show friendlier messages.
sub vcl_error {
  # Redirect to the homepage, which will likely be in the cache.
  set obj.http.Content-Type = "text/html; charset=utf-8";
  synthetic {"
<html>
<head>
  <title>Page Unavailable</title>
  <style>
    body { background: #303030; text-align: center; color: white; }
    #page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0; padding: 30px; background: #323232; }
    a, a:link, a:visited { color: #CCC; }
    .error { color: #222; }
  </style>
</head>
<body onload="setTimeout(function() { window.location = '/' }, 5000)">
  <div id="page">
    <h1 class="title">Page Unavailable</h1>
    <p>The page you requested is temporarily unavailable.</p>
    <p>We're redirecting you to the <a href="/">homepage</a> in 5 seconds.</p>
    <div class="error">(Error "} + obj.status + " " + obj.response + {")</div>
  </div>
</body>
</html>
"};
  return (deliver);
}

And here's how it appears:

textmate vcl highlighting - synthetic keyword

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions