Skip to content

Commit

Permalink
protect against *print-length* messing with data files
Browse files Browse the repository at this point in the history
  • Loading branch information
thheller committed Mar 29, 2018
1 parent 84e9227 commit 0939bb8
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/main/shadow/build/babel.clj
Expand Up @@ -3,6 +3,7 @@
[clojure.core.async :as async :refer (<!! >!!)]
[shadow.build.log :as cljs-log]
[shadow.cljs.util :as util]
[shadow.core-ext :as core-ext]
[clojure.tools.logging :as log])
(:import (java.io PushbackReader Writer InputStreamReader BufferedReader IOException)))

Expand Down Expand Up @@ -54,7 +55,7 @@
(let [line
(-> req
(dissoc ::reply-to)
(pr-str)
(core-ext/safe-pr-str)
(str "\n"))]
(doto out
(.write line)
Expand Down
5 changes: 3 additions & 2 deletions src/main/shadow/build/closure.clj
Expand Up @@ -15,7 +15,8 @@
[clojure.data.json :as json]
[shadow.build.cache :as cache]
[cljs.compiler :as cljs-comp]
[clojure.tools.logging :as log])
[clojure.tools.logging :as log]
[shadow.core-ext :as core-ext])
(:import (java.io StringWriter ByteArrayInputStream FileOutputStream File)
(com.google.javascript.jscomp JSError SourceFile CompilerOptions CustomPassExecutionTime
CommandLineRunner VariableMap SourceMapInput DiagnosticGroups
Expand Down Expand Up @@ -689,7 +690,7 @@
(map :name)
(map (fn [def]
(let [export-name
(-> def name str comp/munge pr-str)]
(-> def name str comp/munge core-ext/safe-pr-str)]
(str export-name ":" (comp/munge def)))))
(str/join ",")
(as-module-exports))
Expand Down
5 changes: 3 additions & 2 deletions src/main/shadow/build/targets/browser.clj
Expand Up @@ -17,7 +17,8 @@
[shadow.build.output :as output]
[shadow.build.closure :as closure]
[shadow.build.data :as data]
[shadow.build.log :as log]))
[shadow.build.log :as log]
[shadow.core-ext :as core-ext]))

(s/def ::entry
(s/or :sym shared/unquoted-simple-symbol?
Expand Down Expand Up @@ -342,7 +343,7 @@
(io/make-parents json-file)

(spit json-file (json module-data))
(spit edn-file (pr-str module-data))
(spit edn-file (core-ext/safe-pr-str module-data))

state
))
Expand Down
5 changes: 3 additions & 2 deletions src/main/shadow/cljs/devtools/api.clj
Expand Up @@ -23,7 +23,8 @@
[shadow.cljs.devtools.server.repl-impl :as repl-impl]
[shadow.cljs.devtools.server.runtime :as runtime]
[shadow.build.output :as output]
[shadow.build.log :as build-log]))
[shadow.build.log :as build-log]
[shadow.core-ext :as core-ext]))

;; nREPL support

Expand Down Expand Up @@ -454,7 +455,7 @@

(spit
(io/file output-dir "bundle-info.edn")
(pr-str bundle-info)))
(core-ext/safe-pr-str bundle-info)))

:done
))
Expand Down
5 changes: 3 additions & 2 deletions src/main/shadow/cljs/devtools/server/web/api.clj
Expand Up @@ -11,7 +11,8 @@
[shadow.cljs.devtools.api :as api]
[shadow.cljs.util :as util]
[hiccup.page :refer (html5)]
[clojure.java.io :as io]))
[clojure.java.io :as io]
[shadow.core-ext :as core-ext]))

(defn index-page [req]
{:status 200
Expand Down Expand Up @@ -82,7 +83,7 @@

{:status 200
:headers {"content-type" "application/edn; charset=utf-8"}
:body (pr-str result)}))
:body (core-ext/safe-pr-str result)}))

(defn get-bundle-info [{:keys [config] :as req} build-id]
(try
Expand Down
5 changes: 3 additions & 2 deletions src/main/shadow/cljs/devtools/server/web/common.clj
Expand Up @@ -2,7 +2,8 @@
(:require [shadow.server.assets :as assets]
[hiccup.page :refer (html5)]
[hiccup.core :refer (html)]
[clojure.java.io :as io]))
[clojure.java.io :as io]
[shadow.core-ext :as core-ext]))

(defn not-found
([req]
Expand All @@ -20,7 +21,7 @@
(defn edn [req data]
{:status 200
:header {"content-type" "application/edn"}
:body (pr-str data)})
:body (core-ext/safe-pr-str data)})

(defn page-boilerplate
[req ^String content]
Expand Down
7 changes: 4 additions & 3 deletions src/main/shadow/cljs/devtools/server/worker/ws.clj
Expand Up @@ -11,7 +11,8 @@
[shadow.http.router :as http]
[shadow.build.data :as data]
[shadow.build.resource :as rc]
[clojure.tools.logging :as log])
[clojure.tools.logging :as log]
[shadow.core-ext :as core-ext])
(:import (java.util UUID)))

(defn ws-loop!
Expand Down Expand Up @@ -162,7 +163,7 @@
result (worker/repl-compile worker-proc input)]
{:status 200
:headers headers
:body (pr-str result)})
:body (core-ext/safe-pr-str result)})

;; bad requests
{:status 400
Expand Down Expand Up @@ -242,7 +243,7 @@
(str prepend js append sm-text)))
})))
(into [])
(pr-str))})
(core-ext/safe-pr-str))})

;; bad requests
{:status 400
Expand Down
11 changes: 11 additions & 0 deletions src/main/shadow/core_ext.clj
@@ -0,0 +1,11 @@
(ns shadow.core-ext)

(defn safe-pr-str
"cider globally sets *print-length* for the nrepl-session which messes with pr-str when used to print cache or other files"
[x]
(binding [*print-length* nil
*print-level* nil
*print-namespaced-maps* nil
*print-meta* nil]
(pr-str x)
))
5 changes: 3 additions & 2 deletions src/main/shadow/undertow.clj
Expand Up @@ -5,7 +5,8 @@
[clojure.core.async.impl.protocols :as async-prot]
[clojure.tools.logging :as log]
[shadow.undertow.impl :as impl]
[clojure.edn :as edn])
[clojure.edn :as edn]
[shadow.core-ext :as core-ext])
(:import (io.undertow Undertow Handlers UndertowOptions)
(io.undertow.websockets WebSocketConnectionCallback)
(io.undertow.server.handlers ResponseCodeHandler BlockingHandler)
Expand Down Expand Up @@ -91,7 +92,7 @@
(async/close! ws-in)
;; try to send message, close everything if that fails
(do (try
(WebSockets/sendTextBlocking (pr-str msg) channel)
(WebSockets/sendTextBlocking (core-ext/safe-pr-str msg) channel)
;; just ignore sending to a closed channel
(catch ClosedChannelException e
(async/close! ws-in)
Expand Down

0 comments on commit 0939bb8

Please sign in to comment.