|
28 | 28 | using System.Runtime.Serialization; |
29 | 29 | using GeneXus.Mime; |
30 | 30 | using System.Text.RegularExpressions; |
| 31 | +using System.Globalization; |
31 | 32 |
|
32 | 33 | namespace GeneXus.Http |
33 | 34 | { |
@@ -82,6 +83,8 @@ public static void SetResponseStatus(HttpContext httpContext, string statusCode, |
82 | 83 | HttpStatusCode httpStatusCode = MapStatusCode(statusCode); |
83 | 84 | SetResponseStatus(httpContext, httpStatusCode, statusDescription); |
84 | 85 | } |
| 86 | + |
| 87 | + |
85 | 88 | public static void SetResponseStatus(HttpContext httpContext, HttpStatusCode httpStatusCode, string statusDescription) |
86 | 89 | { |
87 | 90 | #if !NETCORE |
@@ -339,6 +342,82 @@ public static string[] GetParameterValues(string query) |
339 | 342 | return query.Split(','); |
340 | 343 | } |
341 | 344 | } |
| 345 | + internal static string HtmlEncodeJsonValue(string value) |
| 346 | + { |
| 347 | + return GXUtil.HtmlEncodeInputValue(JsonQuote(value)); |
| 348 | + } |
| 349 | + |
| 350 | + static void AppendCharAsUnicodeJavaScript(StringBuilder builder, char c) |
| 351 | + { |
| 352 | + builder.Append("\\u"); |
| 353 | + int num = c; |
| 354 | + builder.Append(num.ToString("x4", CultureInfo.InvariantCulture)); |
| 355 | + } |
| 356 | + /** |
| 357 | + * Produce a string in double quotes with backslash sequences in all the |
| 358 | + * right places. A backslash will be inserted within </, allowing JSON |
| 359 | + * text to be delivered in HTML. In JSON text, a string cannot contain a |
| 360 | + * control character or an unescaped quote or backslash. |
| 361 | + * */ |
| 362 | + internal static string JsonQuote(string value, bool addDoubleQuotes=false) |
| 363 | + { |
| 364 | + string text = string.Empty; |
| 365 | + if (!string.IsNullOrEmpty(value)) |
| 366 | + { |
| 367 | + int i; |
| 368 | + int len = value.Length; |
| 369 | + StringBuilder sb = new StringBuilder(len + 4); |
| 370 | + |
| 371 | + for (i = 0; i < len; i += 1) |
| 372 | + { |
| 373 | + char c = value[i]; |
| 374 | + switch (c) |
| 375 | + { |
| 376 | + case '\\': |
| 377 | + case '"': |
| 378 | + sb.Append('\\'); |
| 379 | + sb.Append(c); |
| 380 | + break; |
| 381 | + case '\b': |
| 382 | + sb.Append("\\b"); |
| 383 | + break; |
| 384 | + case '\t': |
| 385 | + sb.Append("\\t"); |
| 386 | + break; |
| 387 | + case '\n': |
| 388 | + sb.Append("\\n"); |
| 389 | + break; |
| 390 | + case '\f': |
| 391 | + sb.Append("\\f"); |
| 392 | + break; |
| 393 | + case '\r': |
| 394 | + sb.Append("\\r"); |
| 395 | + break; |
| 396 | + default: |
| 397 | + { |
| 398 | + if (c < ' ') |
| 399 | + { |
| 400 | + AppendCharAsUnicodeJavaScript(sb, c); |
| 401 | + } |
| 402 | + else |
| 403 | + { |
| 404 | + sb.Append(c); |
| 405 | + } |
| 406 | + } |
| 407 | + break; |
| 408 | + } |
| 409 | + } |
| 410 | + text = sb.ToString(); |
| 411 | + } |
| 412 | + if (!addDoubleQuotes) |
| 413 | + { |
| 414 | + return text; |
| 415 | + } |
| 416 | + else |
| 417 | + { |
| 418 | + return "\"" + text + "\""; |
| 419 | + } |
| 420 | + } |
342 | 421 |
|
343 | 422 | } |
344 | 423 | #if NETCORE |
@@ -467,7 +546,7 @@ public static void AddHeader(this HttpResponse response, string name, string val |
467 | 546 |
|
468 | 547 | public static void Write(this HttpResponse response, string value) |
469 | 548 | { |
470 | | - //response.WriteAsync(value).Wait(); |
| 549 | + //response.WriteAsync(value).Wait();//Unsupported by GxHttpAzureResponse |
471 | 550 | response.Body.Write(Encoding.UTF8.GetBytes(value)); |
472 | 551 | } |
473 | 552 | public static void WriteFile(this HttpResponse response, string fileName) |
|
0 commit comments