<commit_before>import settings from 'settings';
import isLink from 'helpers/isLink';

export default function (currentValue, links) {
  let error = '';
  const LINKS_SETTINGS = settings.petitionFields.links;
  const MAX_LINKS = LINKS_SETTINGS.maxLinks;

  if (!isLink(currentValue)) {
    error = LINKS_SETTINGS.invalidLinkFormat;
  } else if (links.length >= MAX_LINKS) {
    error = LINKS_SETTINGS.invalidLinkCount.replace('%x', MAX_LINKS);
  } else if (links.filter(link => (currentValue === link.url)).length) {
    error = LINKS_SETTINGS.invalidSimilarLink;
  }

  return error;
}<commit_msg>Fixed similar URLs with or without protocol<commit_after>import settings from 'settings';
import isLink from 'helpers/isLink';

export default function (currentValue, links) {
  let error = '';
  const LINKS_SETTINGS = settings.petitionFields.links;
  const MAX_LINKS = LINKS_SETTINGS.maxLinks;
  const PROTOCOL_REGEX = new RegExp(/^(https?:\/\/)/i);

  const similarLinks = links.filter(link => (
    currentValue.replace(PROTOCOL_REGEX, '') === link.url.replace(PROTOCOL_REGEX, '')
  ));

  if (!isLink(currentValue)) {
    error = LINKS_SETTINGS.invalidLinkFormat;
  } else if (links.length >= MAX_LINKS) {
    error = LINKS_SETTINGS.invalidLinkCount.replace('%x', MAX_LINKS);
  } else if (similarLinks.length) {
    error = LINKS_SETTINGS.invalidSimilarLink;
  }

  return error;
}
{'fraction_non_alphanumeric': 0.12662807525325614, 'fraction_numerical': 0.0, 'mean_word_length': 4.738589211618257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2111299', 'n_tokens_mistral': 461, 'n_tokens_neox': 452, 'n_words': 95}