curran / curran/google-diff-match-patch

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

Aperta
#100 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
auto-migrated Priority-Medium Type-Defect
Lingua principale
Python
Stelle
17
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

```
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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Individua i riferimenti a System.Web UrlEncode e UrlDecode e la classe CompatibilityExtensions. Leggi come viene compilato e pacchettizzato l'assembly per SQLCLR, quindi verifica che la dipendenza possa essere rimossa mantenendo compatibili la codifica e la decodifica degli URL e che l'assembly possa essere installato con le restrizioni SQL.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, sql
Ambito
databases
Tipo di issue
Refactoring
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.