Repository: vertexproject/synapse

Issue:
[BUG] inet:url not stripping whitespace at the beg
**Describe the bug**
When adding an inet:url node, whitespace is not stripped from the beginning of the str. I couldn't think of a reason that should be allowed. It would help any accidental spacing added by the user. Maybe this is a feature request then?  


**To Reproduce**
`cli> storm [inet:url=" https://x=msn.com"]
Executing query at 2020/05/22 18:12:49.545
.......
inet:url= https://msn.com
        .created = 2020/05/22 18:12:49.559
        :base =  https://msn.com
        :fqdn = msn.com
        :params =
        :path =
        :proto =  https
complete. 1 nodes in 16 ms (62/sec).
cli> storm [inet:url="  https://msn.com"]
Executing query at 2020/05/22 18:12:55.072
.......
inet:url=  https://msn.com
        .created = 2020/05/22 18:12:55.085
        :base =   https://msn.com
        :fqdn = msn.com
        :params =
        :path =
        :proto =   https
complete. 1 nodes in 14 ms (71/sec).`
A clear and concise description of what you expected to happen.

**Environment (please complete the following information):**
 - OS: macos
 - Synapse Version 0.2.0rc16
 - Python Version: 3.7.3
 - Output of `python -m pip freeze`
aiohttp==3.6.2
async-timeout==3.0.1
attrs==19.3.0
cffi==1.14.0
chardet==3.0.4
cryptography==2.9
fastjsonschema==2.14.4
idna==2.9
lark-parser==0.7.8
lmdb==0.98
msgpack==0.6.2
multidict==4.7.5
packaging==20.3
prompt-toolkit==2.0.10
pycparser==2.20
Pygments==2.3.1
pyOpenSSL==19.1.0
pyparsing==2.4.6
PyYAML==5.3.1
regex==2020.2.20
six==1.14.0
synapse==0.2.0rc16
tornado==6.0.4
wcwidth==0.1.9
xxhash==1.4.3
yarl==1.4.2

Discussion:
@invisig0th: Agreed.  We'll include this in the next release that include a data migration.  @invisig0th: Moved this to long-term backlog due to requiring a data migration that would change primary property values ( and therefor node IDs ).  Closing this issue for now. :)@vEpiphyte: @ed4wg This was addressed in #3940 .

Solution patch:
diff --git a/synapse/models/inet.py b/synapse/models/inet.py
index 624603cd624..f855651705d 100644
--- a/synapse/models/inet.py
+++ b/synapse/models/inet.py
@@ -868,6 +868,7 @@ def cmpr(valu):
         return cmpr
 
     def _normPyStr(self, valu):
+        valu = valu.strip()
         orig = valu
         subs = {}
         proto = ''


Test patch:
diff --git a/synapse/tests/test_model_inet.py b/synapse/tests/test_model_inet.py
index d095983aa69..3d484dd615a 100644
--- a/synapse/tests/test_model_inet.py
+++ b/synapse/tests/test_model_inet.py
@@ -1414,6 +1414,18 @@ async def test_url(self):
             }})
             self.eq(valu, expected)
 
+            url = '  http://0.0.0.0/index.html?foo=bar  '
+            valu = t.norm(url)
+            expected = (url.strip(), {'subs': {
+                'proto': 'http',
+                'path': '/index.html',
+                'params': '?foo=bar',
+                'ipv4': 0,
+                'port': 80,
+                'base': 'http://0.0.0.0/index.html'
+            }})
+            self.eq(valu, expected)
+
             unc = '\\\\0--1.ipv6-literal.net\\share\\path\\to\\filename.txt'
             url = 'smb://::1/share/path/to/filename.txt'
             valu = t.norm(unc)