1717 */
1818package org .ice4j .attribute ;
1919
20+ import org .ice4j .*;
21+
2022import java .util .*;
2123
2224/**
@@ -33,6 +35,24 @@ public class UsernameAttribute extends Attribute
3335 */
3436 public static final String NAME = "USERNAME" ;
3537
38+ /**
39+ * The name of the property which controls whether trailing zeroes should
40+ * be stripped when decoding USERNAME attributes.
41+ */
42+ public static final String STRIP_TRAILING_ZEROES_PNAME
43+ = "org.ice4j.attribute.UsernameAttribute.STRIP_TRAILING_ZEROES" ;
44+
45+ /**
46+ * Whether trailing zeroes should be stripped when decoding USERNAME
47+ * attributes. This is necessary to work around a bug in Edge described
48+ * here:
49+ * https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12332457/
50+ * and here:
51+ * https://github.com/jitsi/lib-jitsi-meet/issues/498
52+ */
53+ private boolean stripTrailingZeroes
54+ = StackProperties .getBoolean (STRIP_TRAILING_ZEROES_PNAME , false );
55+
3656 /**
3757 * Username value.
3858 */
@@ -56,8 +76,17 @@ public class UsernameAttribute extends Attribute
5676 * offset is equal to the index of the first byte after length)
5777 * @param length the length of the binary array.
5878 */
79+ @ Override
5980 void decodeAttributeBody (byte [] attributeValue , char offset , char length )
6081 {
82+ if (stripTrailingZeroes )
83+ {
84+ while (length > 0 && attributeValue [offset + length ] == 0 )
85+ {
86+ length --;
87+ }
88+ }
89+
6190 username = new byte [length ];
6291 System .arraycopy (attributeValue , offset , username , 0 , length );
6392 }
0 commit comments