@Test public void testUnescape() { assertEquals("a\"b", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\"b")).toString()); assertEquals("a\\b", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\\b")).toString()); assertEquals("a\\\"b", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\\\\\"b")).toString()); assertEquals("\\\"", VisibilityEvaluator.unescape(new ArrayByteSequence("\\\\\\\"")).toString()); assertEquals("a\\b\\c\\d", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\\b\\\\c\\\\d")).toString()); try { VisibilityEvaluator.unescape(new ArrayByteSequence("a\\b")); fail("Expected failure to unescape invalid escape sequence"); } catch (IllegalArgumentException e) {} try { VisibilityEvaluator.unescape(new ArrayByteSequence("a\\b\\c")); fail("Expected failure to unescape invalid escape sequence"); } catch (IllegalArgumentException e) {} try { VisibilityEvaluator.unescape(new ArrayByteSequence("a\"b\\")); fail("Expected failure to unescape invalid escape sequence"); } catch (IllegalArgumentException e) {} }
static ByteSequence unescape(ByteSequence auth) { int escapeCharCount = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '"' || b == '\\') { escapeCharCount++; } } if (escapeCharCount > 0) { if (escapeCharCount % 2 == 1) { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } byte[] unescapedCopy = new byte[auth.length() - escapeCharCount / 2]; int pos = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '\\') { i++; b = auth.byteAt(i); if (b != '"' && b != '\\') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } } else if (b == '"') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } unescapedCopy[pos++] = b; } return new ArrayByteSequence(unescapedCopy); } else { return auth; } }
VisibilityEvaluator { static ByteSequence unescape(ByteSequence auth) { int escapeCharCount = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '"' || b == '\\') { escapeCharCount++; } } if (escapeCharCount > 0) { if (escapeCharCount % 2 == 1) { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } byte[] unescapedCopy = new byte[auth.length() - escapeCharCount / 2]; int pos = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '\\') { i++; b = auth.byteAt(i); if (b != '"' && b != '\\') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } } else if (b == '"') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } unescapedCopy[pos++] = b; } return new ArrayByteSequence(unescapedCopy); } else { return auth; } } }
VisibilityEvaluator { static ByteSequence unescape(ByteSequence auth) { int escapeCharCount = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '"' || b == '\\') { escapeCharCount++; } } if (escapeCharCount > 0) { if (escapeCharCount % 2 == 1) { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } byte[] unescapedCopy = new byte[auth.length() - escapeCharCount / 2]; int pos = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '\\') { i++; b = auth.byteAt(i); if (b != '"' && b != '\\') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } } else if (b == '"') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } unescapedCopy[pos++] = b; } return new ArrayByteSequence(unescapedCopy); } else { return auth; } } VisibilityEvaluator(AuthorizationContainer authsContainer);  VisibilityEvaluator(Authorizations authorizations); }
VisibilityEvaluator { static ByteSequence unescape(ByteSequence auth) { int escapeCharCount = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '"' || b == '\\') { escapeCharCount++; } } if (escapeCharCount > 0) { if (escapeCharCount % 2 == 1) { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } byte[] unescapedCopy = new byte[auth.length() - escapeCharCount / 2]; int pos = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '\\') { i++; b = auth.byteAt(i); if (b != '"' && b != '\\') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } } else if (b == '"') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } unescapedCopy[pos++] = b; } return new ArrayByteSequence(unescapedCopy); } else { return auth; } } VisibilityEvaluator(AuthorizationContainer authsContainer);  VisibilityEvaluator(Authorizations authorizations); static byte[] escape(byte[] auth, boolean quote); boolean evaluate(ColumnVisibility visibility); }
VisibilityEvaluator { static ByteSequence unescape(ByteSequence auth) { int escapeCharCount = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '"' || b == '\\') { escapeCharCount++; } } if (escapeCharCount > 0) { if (escapeCharCount % 2 == 1) { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } byte[] unescapedCopy = new byte[auth.length() - escapeCharCount / 2]; int pos = 0; for (int i = 0; i < auth.length(); i++) { byte b = auth.byteAt(i); if (b == '\\') { i++; b = auth.byteAt(i); if (b != '"' && b != '\\') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } } else if (b == '"') { throw new IllegalArgumentException("Illegal escape sequence in auth : " + auth); } unescapedCopy[pos++] = b; } return new ArrayByteSequence(unescapedCopy); } else { return auth; } } VisibilityEvaluator(AuthorizationContainer authsContainer);  VisibilityEvaluator(Authorizations authorizations); static byte[] escape(byte[] auth, boolean quote); boolean evaluate(ColumnVisibility visibility);  }