curran / curran/google-diff-match-patch

Consider SQLCLR compatibility / eliminate dependency on System.Web for UrlEncode and UrlDecode

Open
#100 0 comments 0 reactions 0 assignees View on GitHub
auto-migrated Priority-Medium Type-Defect
Dominant language
Python
Stars
17
Forks
2
PR merge metrics
No merged PRs in 30d

Description

```
DiffMatchPatch can be useful as a SQLCLR assembly so methods can be called from
TSQL functions.

However, the dependency on System.Web for UrlEncode and UrlDecode is an
obstacle to installing the assembly into SQL, as System.Web depends on
remoting, which is not allowed under SQL.

I have successfully created and added local UrlEncode and UrlDecode methods to
class CompatibilityExtensions, thereby allowing DiffMatchPatch to be used in a
SQLCLR assembly.

This solution may be useful to others. Please consider removing the dependency
on System.Web

I am providing the URLEncode and URLDecode source that I wrote below, in case
that would be helpful.

//A local UrlEncode, because we can't use System.Web in SQL
//UrlEncode by David Rueter (drueter@assyst.com)
public static string UrlEncode(string s)
{
string output = "";
int p = 0;

Regex regex = new Regex("([^a-zA-Z0-9_.])");

Match match = regex.Match(s);
while (match.Success)
{
if (match.Index > p)
{
output += s.Substring(p, match.Index - p);
}
if (match.Value[0] == ' ')
{
output += '+';
}
else
{
string hexVal = "%" + String.Format("{0:X2}", (int)match.Value[0]);
output += hexVal.ToUpper();
}
p = match.Index + 1;

match = match.NextMatch();
}

if (p < s.Length)
{
output += s.Substring(p);
}

return output;
}

//A local UrlDecode, because we can't use System.Web in SQL
//UrlDecode by David Rueter (drueter@assyst.com)
public static string UrlDecode(string s)
{
string output = "";
int p = 0;

Regex regex = new Regex("([%+])");

Match match = regex.Match(s);
while (match.Success)
{
if (match.Index > p)
{
output += s.Substring(p, match.Index - p);
}
if (match.Value[0] == '+')
{
output += ' ';
p = match.Index + 1;
}
else
{
string hexVal = match.Value.Substring(1, 2);
output += int.Parse(hexVal);
}
p = match.Index + 3;

match = match.NextMatch();
}

if (p < s.Length)
{
output += s.Substring(p);
}

return output;
}
```

Original issue reported on code.google.com by `dbrue...@gmail.com` on 19 Apr 2014 at 7:22

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.