Replace encodeURI() with encodeURIComponent()

encodeURIComponent() is intended for escaping individual components, so it makes more sense here than encodeURI(), which may not encode everything properly.