Recently, I had a bit of a problem with some code I was sending back and forth through Messages. This was caused by smart quotes, which replace single and double quotation marks with directional quotation marks. This can cause a lot of problems. To disable smart quotes:
defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticQuoteSubstitutionEnabled" -bool false