(defun org-babel-update-block-body (new-body)
  "Update the body of the current code block to NEW-BODY."
  (if (not (org-babel-where-is-src-block-head))
      (error "not in source block")
    (save-match-data
      (replace-match (concat (org-babel-trim new-body) "\n") nil t nil 5))
    (indent-rigidly (match-beginning 5) (match-end 5) 2)))

replace-match argument should be t instead of nil (as shown), otherwise \ is treated as a special character and you cant detangle code with that character in it.