weavejester / ring-refresh

A Clojure middleware library for Ring that automatically triggers a browser refresh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Two scripts added when response body includes both `<head>` and `<header>` tags

stevejmp opened this issue · comments

Expected

One script added to the response body, when it includes both <head> and <header> tags.

Actual

Two scripts added to the response body.

Steps to Reproduce

  1. Run a task using ring-refresh in a project
  2. Return a response body with both <head> and <header> tags
    <html>
    <head>
      <title>Title</title>
    </head>
    <body>
      <header>This is a header</header>
    </body>
    </html>
  3. Observe the script being added to the response body twice, in the <head> and <header> tags

Versions

Ring-Refresh 0.1.2 (lein-ring 0.12.6 -> lein-server 0.5.0 -> ring-refresh 0.1.2)
Clojure 1.11.0
Java 11.0.14
Leiningen 2.9.8

More Info

The regex in refresh/add-script is a bit greedy: #"<head\s*[^>]*>"

Fix: Replacing it with @"<head(?!er)\s*[^\/>]*>" seems to accommodate the different scenarios.

PR incoming.