<commit_before>function(newDoc, savedDoc, userCtx) {

  // Handle deletion of existing documents.
  if (newDoc._deleted === true) {
    return true;
  }

  // Regular expression to validate URIs based on the BNF in Appendix A of RFC 2396 (the one given in Appendix B of RFC 2396 is a joke).
  // Thanks to <NAME> for converting the BNF into a regular expression: http://timezra.blogspot.com/2010/05/regex-to-validate-uris.html
  // The support for relative URIs was removed to conform with "RDF: Concepts and Abstract Syntax" and forward slashes were escaped.
  var uriRegEx = /([a-zA-Z][a-zA-Z0-9\+\-\.]*:((((\/\/((((([a-zA-Z0-9\-_\.!\~\*'\(\);:\&=\+$,]|(%[a-fA-F0-9]{2}))*)\@)?((((([a-zA-Z0-9](([a-zA-Z0-9\-])*[a-zA-Z0-9])?)\.)*([a-zA-Z](([a-zA-Z0-9\-])*[a-zA-Z0-9])?)(\.)?)|([0-9]+((\.[0-9]+){3})))(:[0-9]*)?))?|([a-zA-Z0-9\-_\.!\~\*'\(\)$,;:\@\&=\+]|(%[a-fA-F0-9]{2}))+)(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*)(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*))*)?)|(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*)(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*))*))(\?([a-zA-Z0-9\-_\.!\~\*'\(\);/\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)?)|(([a-zA-Z0-9\-_\.!\~\*'\(\);\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))([a-zA-Z0-9\-_\.!\~\*'\(\);/\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)))?(\#([a-zA-Z0-9\-_\.!\~\*'\(\);/\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)?/

  // Handle creation and updates of documents.
  if (!newDoc.subject) {
    throw {
      forbidden: 'subject is required'
    }
  }
  if (!newDoc.subject.match(uriRegExp)) {
    throw {
      forbidden: 'subject has to be a URI'
    }
  }

  if (!newDoc.predicate) {
    throw {
      forbidden: 'predicate is required'
    }
  }
  if (!newDoc.predicate.match(uriRegExp)) {
    throw {
      forbidden: 'predicate has to be a URI'
    }
  }

  if (!newDoc.object) {
    throw {
      forbidden: 'object is required'
    }
  }
  if (!newDoc.object_type) {
    throw {
      forbidden: 'object has to have a type'
    }
  }
  if (newDoc.object_type !== 'URI' && newDoc.object_type !== 'Literal') {
    throw {
      forbidden: 'type of the object has to be either "URI" or "Literal"' + " not " + newDoc.object.type
    }
  }
  if (newDoc.object_type === 'URI' && !newDoc.object.match(uriRegExp)) {
    throw {
      forbidden: 'object is not a valid URI'
    }
  }
  if (newDoc.object_type === 'Literal' && !newDoc.object) {
    throw {
      forbidden: 'object is not a valid literal'
    }
  }

  if (!newDoc.permission) {
    throw {
      forbidden: 'permission is required'
    }
  }
  if (newDoc.permission !== 'public' && newDoc.permission !== 'private') {
    throw {
      forbidden: 'permission has to be either "public" or "private"'
    }
  }

}
<commit_msg>Allow for empty URIs according to RFC 2396. Removed unnecessary check.<commit_after>function(newDoc, savedDoc, userCtx) {

  // Handle deletion of existing documents.
  if (newDoc._deleted === true) {
    return true;
  }

  // Regular expression to validate URIs based on the BNF in Appendix A of RFC 2396 (the one given in Appendix B of RFC 2396 is a joke).
  // Thanks to <NAME> for converting the BNF into a regular expression: http://timezra.blogspot.com/2010/05/regex-to-validate-uris.html
  // The support for relative URIs was removed to conform with "RDF: Concepts and Abstract Syntax" and forward slashes were escaped.
  var uriRegEx = /([a-zA-Z][a-zA-Z0-9\+\-\.]*:((((\/\/((((([a-zA-Z0-9\-_\.!\~\*'\(\);:\&=\+$,]|(%[a-fA-F0-9]{2}))*)\@)?((((([a-zA-Z0-9](([a-zA-Z0-9\-])*[a-zA-Z0-9])?)\.)*([a-zA-Z](([a-zA-Z0-9\-])*[a-zA-Z0-9])?)(\.)?)|([0-9]+((\.[0-9]+){3})))(:[0-9]*)?))?|([a-zA-Z0-9\-_\.!\~\*'\(\)$,;:\@\&=\+]|(%[a-fA-F0-9]{2}))+)(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*)(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*))*)?)|(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*)(\/(([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*(;([a-zA-Z0-9\-_\.!\~\*'\(\):\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)*))*))(\?([a-zA-Z0-9\-_\.!\~\*'\(\);/\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)?)|(([a-zA-Z0-9\-_\.!\~\*'\(\);\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))([a-zA-Z0-9\-_\.!\~\*'\(\);/\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)))?(\#([a-zA-Z0-9\-_\.!\~\*'\(\);/\?:\@\&=\+$,]|(%[a-fA-F0-9]{2}))*)?/

  // Handle creation and updates of documents.
  if (newDoc.subject === undefined) {
    throw {
      forbidden: 'subject is required'
    }
  }
  if (!newDoc.subject.match(uriRegEx)) {
    throw {
      forbidden: 'subject has to be a URI'
    }
  }

  if (newDoc.predicate === undefined) {
    throw {
      forbidden: 'predicate is required'
    }
  }
  if (!newDoc.predicate.match(uriRegEx)) {
    throw {
      forbidden: 'predicate has to be a URI'
    }
  }

  if (newDoc.object === undefined) {
    throw {
      forbidden: 'object is required'
    }
  }
  if (!newDoc.object_type) {
    throw {
      forbidden: 'object has to have a type'
    }
  }
  if (newDoc.object_type !== 'URI' && newDoc.object_type !== 'Literal') {
    throw {
      forbidden: 'type of the object has to be either "URI" or "Literal"' + " not " + newDoc.object.type
    }
  }
  if (newDoc.object_type === 'URI' && !newDoc.object.match(uriRegEx)) {
    throw {
      forbidden: 'object is not a valid URI'
    }
  }

  if (!newDoc.permission) {
    throw {
      forbidden: 'permission is required'
    }
  }
  if (newDoc.permission !== 'public' && newDoc.permission !== 'private') {
    throw {
      forbidden: 'permission has to be either "public" or "private"'
    }
  }

}

{'fraction_non_alphanumeric': 0.3492302543507363, 'fraction_numerical': 0.035140562248995984, 'mean_word_length': 2.6027727546714887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7424557', 'n_tokens_mistral': 2867, 'n_tokens_neox': 2720, 'n_words': 397}