<commit_before><?php
function encodeIllegalChars($input) {
	return preg_replace("/[^a-zA-Z0-9_@=.]/", "_", $input);
}

function getRealmPart($userid) {

	$decomposedID = explode("@", $userid);
	if (isset($decomposedID[1])) {
		return self::encodeIllegalChars($decomposedID[1]);
	}
	return null;
}

function attributealter_groups(&$attributes, $spentityid = null, $idpentityid = null) {

	// We start off with an empty list of groups.
	$groups = array();
	
	/*
	 * Then we add the realm of the user. The part after the @ of the eduPersonPrincipalName
	 */
	$realmpart = getRealmPart($attributes['eduPersonPrincipalName']);
	if (isset($realmpart)) {
		$groups[] = 'realm-' . $realmpart;
	} else {
		$realmpart = 'NA';
	}

	
	/*
	 * Create group membership by the eduPersonAffiliation attribute.
	 */
	if (isset($attributes['eduPersonAffiliation']) && is_array($attributes['eduPersonAffiliation']) ) {
		foreach ($attributes['eduPersonAffiliation'] AS $affiliation) {
			$groups[] = 'affiliation-' . $realmpart . '-' . encodeIllegalChars($affiliation);
		}
	}
	
	/*
	 * Create group membership by the eduPersonOrgUnitDN attribute.
	 */
	if (isset($attributes['eduPersonOrgUnitDN']) && is_array($attributes['eduPersonOrgUnitDN']) ) {
		foreach ($attributes['eduPersonOrgUnitDN'] AS $orgunit) {
			$groups[] = 'orgunit-' . $realmpart . '-' . encodeIllegalChars($orgunit);
		}
	}
	
	if (isset($attributes['eduPersonEntitlement']) && is_array($attributes['eduPersonEntitlement']) ) {
		foreach ($attributes['eduPersonEntitlement'] AS $orgunit) {
			$groups[] = 'entitlement-' . $realmpart . '-' . encodeIllegalChars($orgunit);<commit_msg>Fix group attribute generation code.<commit_after><?php
function encodeIllegalChars($input) {
	return preg_replace("/[^a-zA-Z0-9_@=.]/", "_", $input);
}

function getRealmPart($userid) {

	$decomposedID = explode("@", $userid);
	if (isset($decomposedID[1])) {
		return encodeIllegalChars($decomposedID[1]);
	}
	return null;
}

function attributealter_groups(&$attributes, $spentityid = null, $idpentityid = null) {

	// We start off with an empty list of groups.
	$groups = array();
	
	/*
	 * Then we add the realm of the user. The part after the @ of the eduPersonPrincipalName
	 */
	if(array_key_exists('eduPersonPrincipalName', $attributes)) {
		$realmpart = getRealmPart($attributes['eduPersonPrincipalName'][0]);
	} else {
		$realmpart = NULL;
	}
	if (isset($realmpart)) {
		$groups[] = 'realm-' . $realmpart;
	} else {
		$realmpart = 'NA';
	}

	
	/*
	 * Create group membership by the eduPersonAffiliation attribute.
	 */
	if (isset($attributes['eduPersonAffiliation']) && is_array($attributes['eduPersonAffiliation']) ) {
		foreach ($attributes['eduPersonAffiliation'] AS $affiliation) {
			$groups[] = 'affiliation-' . $realmpart . '-' . encodeIllegalChars($affiliation);
		}
	}
	
	/*
	 * Create group membership by the eduPersonOrgUnitDN attribute.
	 */
	if (isset($attributes['eduPersonOrgUnitDN']) && is_array($attributes['eduPersonOrgUnitDN']) ) {
		foreach ($attributes['eduPersonOrgUnitDN'] AS $orgunit) {
			$groups[] = 'orgunit-' . $realmpart . '-' . encodeIllegalChars($orgunit);
		}
	}
	
	if (isset($attributes['eduPersonEntitlement']) && is_array($attributes['eduPersonEntitlement']) ) {
		foreach ($attributes['eduPersonEntitlement'] AS $orgunit) {
			$groups[] = 'entitlement-' . $realmpart . '-' . encodeIllegalChars($orgunit);
{'fraction_non_alphanumeric': 0.16923076923076924, 'fraction_numerical': 0.0026627218934911242, 'mean_word_length': 4.99468085106383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7287330', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1099, 'n_words': 220}