Проблемы кодирования HTML - символ “Â”, обнаруживающийся вместо “&nbsp”;

На самом деле, скрытая функция спецификации: Вы можете;-p

decimal bankBalance = (decimal)3433.20;

Это действительно анализируется компилятором как десятичное число (не плавание и бросок). Посмотрите IL для доказательства его. Обратите внимание, что точность становится усеченной, хотя (это имеет 1 десятичную цифру, не 2, Вы добираетесь от M версия).

IL генерировал:

L_0001: ldc.i4 0x861c
L_0006: ldc.i4.0 
L_0007: ldc.i4.0 
L_0008: ldc.i4.0 
L_0009: ldc.i4.1 
L_000a: newobj instance void [mscorlib]System.Decimal::.ctor(int32, int32, int32, bool, uint8)
L_000f: stloc.0 

По сравнению с:

decimal bankBalance = 3433.20M;

, Который генерирует:

L_0001: ldc.i4 0x53d18
L_0006: ldc.i4.0 
L_0007: ldc.i4.0 
L_0008: ldc.i4.0 
L_0009: ldc.i4.2 
L_000a: newobj instance void [mscorlib]System.Decimal::.ctor(int32, int32, int32, bool, uint8)
L_000f: stloc.0 

единственной разницей являются десятичные цифры (1 по сравнению с 2, и фактор 10, соответственно)

197
задан Cᴏʀʏ 22 February 2017 в 13:40
поделиться

1 ответ

Somewhere in that mess, the non-breaking spaces from the HTML template (the s) are encoding as ISO-8859-1 so that they show up incorrectly as an "Â" character

That'd be encoding to UTF-8 then, not ISO-8859-1. The non-breaking space character is byte 0xA0 in ISO-8859-1; when encoded to UTF-8 it'd be 0xC2,0xA0, which, if you (incorrectly) view it as ISO-8859-1 comes out as "Â ". That includes a trailing nbsp which you might not be noticing; if that byte isn't there, then something else has mauled your document and we need to see further up to find out what.

What's the regexp, how does the templating work? There would seem to be a proper HTML parser involved somewhere if your   strings are (correctly) being turned into U+00A0 NON-BREAKING SPACE characters. If so, you could just process your template natively in the DOM, and ask it to serialise using the ASCII encoding to keep non-ASCII characters as character references. That would also stop you having to do regex post-processing on the HTML itself, which is always a highly dodgy business.

Well anyway, for now you can add one of the following to your document's and see if that makes it look right in the browser:

  • for HTML4:
  • for HTML5:

If you've done that, then any remaining problem is ActivePDF's fault.

329
ответ дан 23 November 2019 в 05:15
поделиться
Другие вопросы по тегам:

Похожие вопросы: