Commit Graph
35 Commits
Author SHA1 Message Date
Marcos Henrich 3d332ac26d Added UTF8EncodingTest.EncodingFallback.
EncodingFallback tests for multiple invalid inputs the unknownBytes that are given to the DecoderFallback.
2014-09-02 22:55:52 +08:00
Martin Potter 1b318701b9 Fixing bugs in UTF8Encoding's GetMaxByteCount and GetMaxCharCount.
The previous implementation of GetMaxByteCount has two bugs: it incorrectly took into account the byte order mark and it was taking the max of a byte count (3) and a character count (EncoderFallback.MaxCharCount). This could result in returning the max number of bytes required to convert a string that was less than the number bytes used when converting the string.

GetMaxCharCount did not previously take into account DecoderFallback.MaxCharCount or the fact that there may still be part of a surrogate pair left on the buffer from a previous call to convert.

I removed the #if NET_2_0 conditionals and NotWorking category since these methods now return results consistent with Microsoft's implementation. I also added two simple tests for custom EncoderFallback and DecoderFallback cases.

This commit is licensed under MIT/X11.
2013-10-13 14:37:45 -07:00
Atsushi Eno 132a16ca07 Revert "Merge pull request #622 from killabytenow/master"
This reverts commit 392bae3c45, reversing
changes made to 61cd9ee8b6.
2013-07-13 23:56:59 +09:00
Gerardo García Peña 2e6266606a Reverted changes of commit 6ad7f75a37 2013-07-11 23:52:35 +02:00
Gerardo García Peña 9d55be425d An #if has been negated (bugfix) 2013-07-10 11:26:26 +02:00
Gerardo García Peña 04ffec1684 Added new test for checking EncoderFallbackException exception behaviour. 2013-07-09 16:22:37 +02:00
Gerardo García Peña ef205e5df2 Added new test for checking DecoderFallbackException exception behaviour. 2013-07-08 23:31:06 +02:00
Gerardo García Peña 6ad7f75a37 in test SufficientByteArray() when !NET_2_0 unexpected exceptions should be forwarded. 2013-05-23 08:43:13 +02:00
Rodrigo Kumpera abe9dc6206 Revert "Fix object::GetType when remoting is enabled."
This reverts commit 93e2d1dc48.
2013-03-01 10:54:09 -05:00
Rodrigo Kumpera 93e2d1dc48 Fix object::GetType when remoting is enabled. 2013-03-01 10:52:03 -05:00
Martin Potter 643d8b8b3a System.Text.Decoder throws ArgumentOutOfRangeException when it should not. Fixes Bug #10789
Similar to previously reported bug #6404, according to the documentation at http://msdn.microsoft.com/en-us/library/h6w985hz.aspx, System.Text.Encoder throws ArgumentOutOfRangeExceptions when it should not. From the documentation, an ArgumentOutOfRangeException should be thrown when:

charIndex, charCount, byteIndex, or byteCount is less than zero.
-or-
The length of chars - charIndex is less than charCount.
-or-
The length of bytes - byteIndex is less than byteCount.

To reproduce, run the following code:

int charsUsed, bytesUsed;
bool completed;
byte[] bytes = new byte[4096];
char[] chars = new char[4096];
System.Text.Encoding.UTF8.GetDecoder().Convert(bytes, 0, 0, chars, 4096, 0, false, out bytesUsed, out charsUsed, out completed);

Expected:

The code runs, charsUsed equals zero, bytesUsed equals zero and completed is true.

Actual:

Mono throws an ArgumentOutOfRangeException for charIndex.

There are also other behavioral differences between Mono and Microsoft's implementation for the GetChars(Byte[], Int32, Int32, Char[], Int32, Boolean) method, such as:

byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes, 0, 0, chars, 10, false);

On Mono, this results in an ArgumentOutOfRangeException for charIndex, where for Microsoft charactersWritten = 0.

Similarly:

byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes, 0, 4096, chars, 10, false);

On Mono, this results in the same ArgumentOutOfRangeException for charIndex, where Microsoft throws and ArgumentException. since "chars does not have enough capacity from charIndex to the end of the array to accommodate the resulting characters."
2013-03-01 05:05:34 -08:00
Martin Potter 7ca2aa01d7 UTF8Decoder.GetChars(Byte[], Int32, Int32, Char[], Int32, Boolean) can write past end of char[]. Fixes Bug#10788
UTF8Decoder.GetChars(Byte[], Int32, Int32, Char[], Int32, Boolean) eventually calls into UTF8Encoding.InternalGetChars, which does not perform any bounds checking on the passed in char* until after the first byte > 0x80 is encountered. For instance:

byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes,
0, 4096, chars, 9, false);

will result in no errors and charactersWritten = 4096.
2013-02-28 16:26:02 -08:00
Marek Safar afa79435aa Update for mobile profile 2013-02-07 16:34:21 +01:00
Atsushi Eno f4aff310cf EncoderFallback support in UTF8Encoding. Fixed bug #565129 and regression in d961246.
Patch mostly by JB Evain.
2010-08-10 20:22:52 +09:00
Marek Habersack 7e0a0a69f0 Revert "EncoderFallback support in UTF8Encoding. Fixed bug #565129."
This reverts commit d961246014 because it breaks 2 tests in
System.Web on 2.0 and 4 on 4.0 profile.
2010-08-05 15:32:58 +02:00
atsushieno d961246014 EncoderFallback support in UTF8Encoding. Fixed bug #565129.
Patch mostly by JB Evain.
2010-08-04 15:32:54 +09:00
Miguel de Icaza 9afbbceb72 2009-07-28 Miguel de Icaza <[email protected]>
* UTF8Encoding.cs: Use Equals to compare the objects as the
	fallback objects do not overload operator ==.    The comparison
	was previously failing.

svn path=/trunk/mcs/; revision=138786
2009-07-28 05:04:08 +00:00
Robert Jordan a5b5163351 2009-06-26 Robert Jordan <[email protected]>
* UTF8EncodingTest.cs: Fix the NET_1_1 build.


svn path=/trunk/mcs/; revision=137012
2009-06-26 21:53:51 +00:00
Zoltan Varga 67b04fd53a 2009-06-26 Zoltan Varga <[email protected]>
* *.cs: Convert all tests to new-style nunit classes/methods. Add
	[Test] attributes to some tests which were missing them.

svn path=/trunk/mcs/; revision=136944
2009-06-26 11:16:10 +00:00
Atsushi Eno 3ef06e62ed 2009-01-30 Atsushi Enomoto <[email protected]>
* UTF8Encoding.cs : surrogate characters are handled in 
	  InternalGetChars() but not in InternalGetCharCount().
	  Fixed bug #415628.

	* UTF8EncodingTest.cs : added test for bug #415628.

	* 415628.bin : new test resource.

	* Makefile: new resource, new EXTRA_DIST mess.


svn path=/trunk/mcs/; revision=125075
2009-01-30 12:13:56 +00:00
Atsushi Eno 1ab79d0289 2007-10-26 Atsushi Enomoto <[email protected]>
* UTF8EncodingTest.cs : looks like the issue is not fixed in .NET 1.x
	  and hence it looked like a regression. (It wasn't.)


svn path=/trunk/mcs/; revision=88248
2007-10-26 04:19:51 +00:00
Atsushi Eno f4071fef2b 2007-10-25 Atsushi Enomoto <[email protected]>
* DecoderReplacementFallbackBuffer.cs : Reset() should also reset the
	  input buffer. When fallback is not assigned, just return '\0'.
	* UnicodeEncoding.cs : handle throwOnInvalid .ctor argument.
	  Default replacement fallback buffer is now "\uFFFD".
	* UTF8Encoding.cs : couple of replacement buffer size fixes.
	  Default replacement fallback buffer is now "\uFFFD".
	* UTF32Encoding.cs : Default replacement is "\uFFFD" too here.
	  See http://support.microsoft.com/kb/940521/ for this change.

	* UnicodeEncodingTest.cs,
	  UTF8EncodingTest.cs,
	  DecoderReplacementFallbackBufferTest.cs,
	  DecoderReplacementFallbackTest.cs : default replacement buffer fix.
	  Added test for Reset() for replacement buffer.


svn path=/trunk/mcs/; revision=88150
2007-10-25 09:42:03 +00:00
Gert Driesen 797ad860d5 * UTF8Encoding.cs: IsMailNewsSave should return true. Fixes bug
#332515.
* UTF32Encoding.cs: IsBrowserSave returns false for both Big-Endian and
Little-Endian.
* TestEncoding.cs: Also make class available on 1.0 profile.
* EncodingTest.cs: Added tests for Is* properties.
* UTF7EncodingTest.cs: Added tests for Is* properties.
* UnicodeEncodingTest.cs: Added tests for Is* properties. Fixed 
line endings.
* UTF8EncodingTest.cs: Added tests for Is* properties. Spaces to
tabs. Numbered tests.
* ASCIIEncodingTest.cs: Added tests for Is* properties. No longer
derive from TestCase class. Spaces to tabs.    
* UTF32EncodingTest.cs: Added tests for Is* properties. No longer
derive from deprecated Assertion class.

svn path=/trunk/mcs/; revision=87593
2007-10-16 14:48:47 +00:00
Atsushi Eno ce4d8a502d 2006-02-14 Atsushi Enomoto <[email protected]>
* UTF8Encoding.cs : Fallback was indicating incorrect index.
	  Fixed bug #77550.

	* UTF8EncodingTest.cs : test for bug #77550.


svn path=/trunk/mcs/; revision=56848
2006-02-14 10:31:51 +00:00
Atsushi Eno e85a1fe77c 2006-02-03 Atsushi Enomoto <[email protected]>
* UTF8Encoding.cs : In zero-charbuffer case, byte buffer count should
	  be checked. Also it should not ignore leftOver characters even if
	  byte buffer length is 0.

	* UTF8EncodingTest.cs : added test for insufficient bytes for
	  flush=true and leftOver!='\0' case.


svn path=/trunk/mcs/; revision=56533
2006-02-03 16:54:56 +00:00
Atsushi Eno fb852c038d 2006-01-24 Atsushi Enomoto <[email protected]>
* UTF7Encoding.cs UTF8Encoding.cs :
	  Fixed bug #77315 (Patch by [email protected]).
	  Make strict check for invalid surrogate.

	* UTF7EncodingTest.cs : added test for bug #77315.
	* UTF8EncodingTest.cs : added test for bug #77315. Also, now a
	  bunch of tests are working (while they are marked as NotDotNet
	  under 1.1 profile).


svn path=/trunk/mcs/; revision=55971
2006-01-24 07:53:12 +00:00
Atsushi Eno 3c311bcdc0 2006-01-20 Atsushi Enomoto <[email protected]>
* Encoding.cs : Cloned instances should not be read-only.

	* UTF8EncodingTest.cs : added CloneNotReadOnly().


svn path=/trunk/mcs/; revision=55823
2006-01-20 08:21:53 +00:00
Atsushi Eno 37c22e54fb 2006-01-19 Atsushi Enomoto <[email protected]>
* UTF7EncodingTest.cs UTF8EncodingTest.cs UnicodeEncodingTest.cs :
	  due to the introduction of fallback, some of their internals have
	  changed. Thus marked some tests as NotWorking.
	* DecoderReplacementFallbackBufferTest.cs,
	  EncoderReplacementFallbackBufferTest.cs :
	  some behaviors have changed since beta2, so marked old tests as
	  NotWorking.


svn path=/trunk/mcs/; revision=55794
2006-01-19 17:08:13 +00:00
Atsushi Eno e14f1bcad3 2005-11-16 Atsushi Enomoto <[email protected]>
* Decoder.cs : added FallbackBuffer property.
	* UTF8Encoding.cs : In NET_2_0, use DecoderFallbackBuffer instead of
	  "throwOnInvalid".

	* UTF8EncodingTest.cs : Simply replaced all ArgumentException with
	  switched alias (it is DecodefFallbackException in NET_2_0).


svn path=/trunk/mcs/; revision=53137
2005-11-16 18:37:52 +00:00
Atsushi Eno 8b1efba385 2005-08-25 Atsushi Enomoto <[email protected]>
in mcs:
	* driver.cs : Use default encoding on the environment.
	  Removed (now that) extra parameter for SeekableStreamReader.
	* support.cs : (SeekableStreamReader) third .ctor() argument for
	  StreamReader is not required (always true). preamble size could
	  be acquired in simpler and safe way.

in tests:
	* test-444.cs :
	  UTF-8 BOM autodetect test (for encoding detection patch).

in class/corlib/System.Text:
	* UTF8Encoding.cs : (InternalGetChars/InternalGetCharCount):
	  Don't exclude FEFF in the resulting text.

in class/corlib/Test/System.Text:
	* UTF8EncodingTest.cs : added GetCharsFEFF().

in class/Managed.Windows.Forms:
	* Makefile : added /codepage:65001 (otherwise the build gets broken
	  on KeyboardLayout.cs on some non-iso-8859-1 environment).


svn path=/trunk/mcs/; revision=48826
2005-08-25 10:41:47 +00:00
Atsushi Eno 8dcd4adc79 2004-06-07 Atsushi Enomoto <[email protected]>
* UTF8EncodingTest.cs : Added TestThrowOnInvalid().

svn path=/trunk/mcs/; revision=28979
2004-06-07 17:53:40 +00:00
Sebastien Pouliot 9993e4e210 2004-05-14 Sebastien Pouliot <[email protected]>
* UTF8EncodingTest.cs: Test both characters in test 2.1.4.

svn path=/trunk/mcs/; revision=27404
2004-05-14 13:33:10 +00:00
Sebastien Pouliot 124190248e 2004-04-14 Sebastien Pouliot <[email protected]>
* UTF8EncodingTest.cs: Ajusted test 3.3.6 and 3.3.7 because MS accept
	invalid UTF8 (when it shouldn't) and Mono doesn't. Both case are now
	accepted by the unit tests.

svn path=/trunk/mcs/; revision=25486
2004-04-14 16:09:29 +00:00
Sebastien Pouliot d3cc9890c9 2004-04-14 Sebastien Pouliot <[email protected]>
* UTF8EncodingTest.cs: Added 70 new unit tests from UTF-8-test.txt
	(available from http://www.cl.cam.ac.uk/~mgk25/). Tests are adapted
	so MS implementation pass them all.

svn path=/trunk/mcs/; revision=25476
2004-04-14 15:05:37 +00:00
Nick Drochak dc91409cfd 2003-05-14 Nick Drochak <[email protected]>
* UTF7EncodingTest.cs:
	* UTF8EncodingTest.cs: added from Patrick Kalkman <[email protected]>

svn path=/trunk/mcs/; revision=14538
2003-05-13 15:28:26 +00:00