<commit_before>const { URL } = require('url');

const instance = require('../helpers/weak_cache');
const { InvalidTarget } = require('../helpers/errors');

module.exports = function checkResourceFormat({ oidc: { params, provider } }, next) {
  if (!instance(provider).configuration('features.resourceIndicators') || params.resource === undefined) {
    return next();
  }

  let { resource: resources } = params;
  if (!Array.isArray(resources)) {
    resources = [resources];
  }

  resources.forEach((resource) => {
    let href;
    try {
      ({ href } = new URL(resource));
    } catch (err) {
      throw new InvalidTarget('resource must be an absolute URI');
    }

    // NOTE: we don't check for new URL() => search of hash because of an edge case
    // new URL('https://example.com?#') => search and hash are empty, seems like an inconsistent validation
    if (href.includes('#')) {
      throw new InvalidTarget('resource must not contain a fragment component');
    }
  });

  return next();
};<commit_msg>fix: properly check if resourceIndicators is enabled<commit_after>const { URL } = require('url');

const instance = require('../helpers/weak_cache');
const { InvalidTarget } = require('../helpers/errors');

module.exports = function checkResourceFormat({ oidc: { params, provider } }, next) {
  if (!instance(provider).configuration('features.resourceIndicators.enabled') || params.resource === undefined) {
    return next();
  }

  let { resource: resources } = params;
  if (!Array.isArray(resources)) {
    resources = [resources];
  }

  resources.forEach((resource) => {
    let href;
    try {
      ({ href } = new URL(resource));
    } catch (err) {
      throw new InvalidTarget('resource must be an absolute URI');
    }

    // NOTE: we don't check for new URL() => search of hash because of an edge case
    // new URL('https://example.com?#') => search and hash are empty, seems like an inconsistent validation
    if (href.includes('#')) {
      throw new InvalidTarget('resource must not contain a fragment component');
    }
  });

  return next();
};
{'fraction_non_alphanumeric': 0.15126854954523697, 'fraction_numerical': 0.0, 'mean_word_length': 3.5238095238095237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '1866162', 'n_tokens_mistral': 575, 'n_tokens_neox': 568, 'n_words': 180}