rdiankov / openrave

Open Robotics Automation Virtual Environment: An environment for testing, developing, and deploying robotics motion planning algorithms.
http://www.openrave.org
Other
693 stars 343 forks source link

New regex for matching URIs and unix file paths in libopenrave-core #1261

Open undisputed-seraphim opened 1 year ago

undisputed-seraphim commented 1 year ago

The current regex used to detect if a string is a URI (last revised 10 years ago) does not infact work as intended.

Due to that fact, there are multiple places that do unnecessary string comparisons to make up for the deficiencies. For example, this function , where a MsgPack file must first run 3 fairly expensive regex matching operations (where the input are identical and results are discarded) before arriving at the function to call.

As well as these functions where the URIs are parsed and resolved again when they should have been resolved in the upper calling layers of code.

Additionally, there are separate functions for loading a KinBody or Scene depending if the intended input is a unix file path or a URI, but there is no real difference between these two (a file path is a URI without a scheme).

I'd like to suggest that first we fix the regex, then try to deduplicate the code contained in libopenrave-core. ReadRobotURI, ReadRobotFile, ReadKinBodyURI, and ReadKinBodyFile are mostly identical functions with minor variations, as are the RaveRead[JSON/MsgPack][URI/File/Data] functions.

A single Load function can detect whether a (non-data) string is a unix file or URI at the very beginning with one regex operation. The string is decomposed into scheme, authority, path, query, and fragment. A download operation is needed if and only if the scheme and authority is non-empty.