clj-commons/camel-snake-kebab

Null Pointer Exception when separator is only character in string

Biserkov opened this issue · 5 comments

Instead of returning the string unchanged, this

(camel-snake-kebab.core/->snake_case "a" :separator \a)
results in

NullPointerException 
	clojure.string/lower-case (string.clj:217)
	clojure.string/lower-case (string.clj:213)
	camel-snake-kebab.internals.misc/convert-case (misc.cljc:8)
	camel-snake-kebab.internals.misc/convert-case (misc.cljc:5)
	clojure.core/apply (core.clj:673)
	clojure.core/apply (core.clj:660)
	camel-snake-kebab.core/->snake-case/convert-case--1573--auto----1639 (core.cljc:20)
	camel-snake-kebab.internals.alter-name/eval1554/fn--1555 (alter_name.cljc:11)
	camel-snake-kebab.internals.alter-name/eval1535/fn--1536/G--1526--1543 (alter_name.cljc:4)
	camel-snake-kebab.core/->snake-case (core.cljc:20)
	camel-snake-kebab.core/->snake-case (core.cljc:20)
qerub commented

Hej and thanks for the report. While looking into this, I noticed that camel-snake-kebab.internals.string-separator/split behaves differently in Clojure[Script] because String#split works differently in Java[Script]. I think we need to solve that first.

Hej, I also made a PR. It's a 1-line change, wrapping the call to (first-fn first) in an if with empty string as the fallback. AND it doesn't interfere with split which happens earlier ;-)

https://github.com/clj-commons/camel-snake-kebab/pull/66/files

qerub commented

It does not interfere but it does interact. Your example (camel-snake-kebab.core/->snake_case "a" :separator \a) gives different results on CLJ and CLJS.

qerub commented

It does not interfere but it does interact. Your example (camel-snake-kebab.core/->snake_case "a" :separator \a) gives different results on CLJ and CLJS.

I've addressed this issue in #68 and reviewed #66 that got unblocked.

Thank you!