Skip to content

Commit

Permalink
fix: Works around a bug in Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Jun 23, 2017
1 parent 51baa62 commit feecace
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/org/ice4j/attribute/UsernameAttribute.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/ */
package org.ice4j.attribute; package org.ice4j.attribute;


import org.ice4j.*;

import java.util.*; import java.util.*;


/** /**
Expand All @@ -33,6 +35,24 @@ public class UsernameAttribute extends Attribute
*/ */
public static final String NAME = "USERNAME"; public static final String NAME = "USERNAME";


/**
* The name of the property which controls whether trailing zeroes should
* be stripped when decoding USERNAME attributes.
*/
public static final String STRIP_TRAILING_ZEROES_PNAME
= "org.ice4j.attribute.UsernameAttribute.STRIP_TRAILING_ZEROES";

/**
* Whether trailing zeroes should be stripped when decoding USERNAME
* attributes. This is necessary to work around a bug in Edge described
* here:
* https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12332457/
* and here:
* https://github.com/jitsi/lib-jitsi-meet/issues/498
*/
private boolean stripTrailingZeroes
= StackProperties.getBoolean(STRIP_TRAILING_ZEROES_PNAME, false);

/** /**
* Username value. * Username value.
*/ */
Expand All @@ -56,8 +76,17 @@ public class UsernameAttribute extends Attribute
* offset is equal to the index of the first byte after length) * offset is equal to the index of the first byte after length)
* @param length the length of the binary array. * @param length the length of the binary array.
*/ */
@Override
void decodeAttributeBody(byte[] attributeValue, char offset, char length) void decodeAttributeBody(byte[] attributeValue, char offset, char length)
{ {
if (stripTrailingZeroes)
{
while (length > 0 && attributeValue[offset + length] == 0)
{
length--;
}
}

username = new byte[length]; username = new byte[length];
System.arraycopy(attributeValue, offset, username, 0, length); System.arraycopy(attributeValue, offset, username, 0, length);
} }
Expand Down

0 comments on commit feecace

Please sign in to comment.