Browse files

librato/safe-name: fix a bug which broke metric name escaping

Invalid characters which were replaced and changed the length of the
string caused safe-name to (sometimes) call subs with a length larger
than the string itself, throwing an exception.
  • Loading branch information...
1 parent 95c7caf commit 72e23737f62ada01278f8debf85e0b4c249e4e0c @aphyr aphyr committed Jan 2, 2013
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/riemann/librato.clj
View
11 src/riemann/librato.clj
@@ -5,13 +5,14 @@
clojure.math.numeric-tower))
(defn safe-name
- "Converts a string into a safe name for Librato's metrics and streams. Converts spaces to periods, preserves only A-Za-z0-9.:-_, and cuts to 255 characters."
+ "Converts a string into a safe name for Librato's metrics and streams.
+ Converts spaces to periods, preserves only A-Za-z0-9.:-_, and cuts to 255
+ characters."
[s]
(when s
- (-> s
- (string/replace " " ".")
- (string/replace #"[^-.:_\w]" "")
- (subs 0 (min 255 (count s))))))
+ (let [s (string/replace s " " ".")
+ s (string/replace s #"[^-.:_\w]" "")]
+ (subs s 0 (min 255 (count s))))))
(defn event->gauge
"Converts an event to a gauge."

0 comments on commit 72e2373

Please sign in to comment.