Ok I have applied both those fixes now and checked that $gal_settings['leading_space'] definately equals 1 when safe mode is enabled, however it still doesn't work properly with urls.
Example:
I added google and
http://www.google.com into settings to be replaced as a test.
the post consisted of
www.google.com
it attempts to replace the google in that url and therefore breaks the url even though the leading space option is properly set and being retrieved correctly.