usnistgov / jsip

JSIP: Java SIP specification Reference Implementation (moved from java.net)
Other
288 stars 131 forks source link

AcceptLanguageParserTest is in failure #74

Open JordanTerri opened 3 years ago

JordanTerri commented 3 years ago

The test doesn't pass when executed.

start gov.nist.javax.sip.parser.AcceptLanguageParserTest
Accept-Language:  da   
Encoded header = Accept-Language: da

Accept-Language: 
Encoded header = Accept-Language: 

Accept-Language: ,
Encoded header = Accept-Language: 

done gov.nist.javax.sip.parser.AcceptLanguageParserTest

testParser(gov.nist.javax.sip.parser.AcceptLanguageParserTest)  Time elapsed: 0.02 sec  <<< FAILURE!
junit.framework.AssertionFailedError: expected:<Accept-Language: 
> but was:<Accept-Language: 
>
    at junit.framework.Assert.fail(Assert.java:57)
    at junit.framework.Assert.failNotEquals(Assert.java:329)
vladimirralev commented 3 years ago

I'll check it out

balgillo commented 2 years ago

It looks like AcceptLanguageParser.parse creates an AcceptLanguageList containing two empty AcceptLanguage objects (i.e. with languageRange == null) from this string:

Accept-Language: ,\n

Then the test converts that back to a string using ((SIPHeader) hdr.clone()).encode().trim() + "\n" and gets this different string:

Accept-Language:\n

This is then parsed to get an AcceptLanguageList containing one empty AcceptLanguage object, which does not match the first AcceptLanguageList which had two of them.

I believe that empty languages should not be added to the accept list:

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#14.4

language-range   = (1*8ALPHA *("-" 1*8alphanum)) / "*"

So, a language-range cannot be an empty string, it must contain an alphabetical character or be *.

The fix then would be for AcceptLanguageParser to ignore empty language ranges, and ParserTestCase.testParser not to expect that "List should contain at least 1 header".