Skip to content

Commit 3de659e

Browse files
committed
PD-4764 Removed invalid chars at the end of issn value, consolidate the UI issn validation for editorial services and work
1 parent 9f9d5fb commit 3de659e

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

‎src/app/constants.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ export const ORCID_URI_REGEXP =
4848
// https://regex101.com/r/M1fqZi/1
4949
export const URL_REGEXP =
5050
/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#%[\]@!\$&'\(\)\*\+\\,;=.>< ]+$/i
51-
// ISSN pattern using same validation as the backend
52-
//https://regex101.com/r/NYZTYS/1
53-
export const ISSN_REGEXP = /\b\d{4}-?\d{3}[\dXx]\b/
51+
export const ISSN_PORTAL_URL = 'https://portal.issn.org/resource/ISSN/'
52+
// Escape the URL characters for Regex (handling slashes and dots)
53+
const escapedUrl = ISSN_PORTAL_URL.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
54+
export const ISSN_REGEXP = new RegExp(`^(?:${escapedUrl})?\\d{4}-?\\d{3}[\\dXx]$`);
55+
56+
5457
/* PROTOCOL REQUIRED*/
5558
// https://regex101.com/r/pSnDC7/1
5659
export const URL_REGEXP_BACKEND =
@@ -516,3 +519,23 @@ function isValidIsbn13(isbn: string): boolean {
516519
// The checksum must be perfectly divisible by 10.
517520
return checksum % 10 === 0
518521
}
522+
523+
524+
function normaliseIssn(issn: string): string {
525+
if (issn) {
526+
// 1. Remove the portal URL
527+
issn = issn.replace(new RegExp(ISSN_PORTAL_URL, 'g'), '')
528+
529+
// 2. Remove ALL non-alphanumeric characters (spaces, hyphens, dots, etc.)
530+
issn = issn.replace(/[^a-zA-Z0-9]/g, '')
531+
532+
// 3. Force 'X' to uppercase
533+
issn = issn.replace(/x/g, 'X')
534+
535+
// 4. Format as 0000-000X if valid length
536+
if (issn.length === 8) {
537+
return issn.substring(0, 4) + '-' + issn.substring(4, 8)
538+
}
539+
}
540+
return ''
541+
}

‎src/app/record/components/affiliation-stacks-groups/modals/modal-affiliations/modal-affiliations.component.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { RecordCountriesService } from '../../../../../core/record-countries/rec
2727
import { first, map, switchMap, tap } from 'rxjs/operators'
2828
import {
2929
ISSN_REGEXP,
30+
ISSN_PORTAL_URL,
3031
MAX_LENGTH_LESS_THAN_ONE_THOUSAND,
3132
MAX_LENGTH_LESS_THAN_TWO_THOUSAND,
3233
URL_REGEXP,
@@ -63,7 +64,6 @@ export class ModalAffiliationsComponent implements OnInit, OnDestroy {
6364
issnLabel = $localize`:@@shared.link:Link`
6465
endDateLabel = $localize`:@@shared.endDate:End date`
6566

66-
ISSN_PORTAL_URL = 'https://portal.issn.org/resource/ISSN/'
6767

6868
private _type: AffiliationType
6969
dateLabel: string
@@ -394,13 +394,14 @@ export class ModalAffiliationsComponent implements OnInit, OnDestroy {
394394
const normalizedIssn = this.normaliseIssn(
395395
affiliationForm.get('issn')?.value?.trim()
396396
)
397-
const issnUrl = `${this.ISSN_PORTAL_URL}${normalizedIssn}`
397+
const issnValue = affiliationForm.get('issn')?.value?.trim();
398+
const issnUrl = `${ISSN_PORTAL_URL}${normalizedIssn}`
398399
affiliationToSave.affiliationExternalIdentifiers = [
399400
{
400401
errors: [],
401402
externalIdentifierId: {
402403
errors: [],
403-
value: affiliationForm.get('issn')?.value?.trim(),
404+
value: issnValue && issnValue.startsWith(ISSN_PORTAL_URL)?issnUrl:normalizedIssn,
404405
required: true,
405406
},
406407
externalIdentifierType: { value: 'issn' },
@@ -744,7 +745,7 @@ export class ModalAffiliationsComponent implements OnInit, OnDestroy {
744745
normaliseIssn(issn: string) {
745746
if (issn) {
746747
// 1. Remove the portal URL
747-
issn = issn.replace(new RegExp(this.ISSN_PORTAL_URL, 'g'), '')
748+
issn = issn.replace(new RegExp(ISSN_PORTAL_URL, 'g'), '')
748749

749750
// 2. Remove ALL non-alphanumeric characters (spaces, hyphens, dots, etc.)
750751
issn = issn.replace(/[^a-zA-Z0-9]/g, '')

‎src/app/record/components/work-form/work-form/work-form.component.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
MAX_LENGTH_LESS_THAN_TWO_THOUSAND,
3838
URL_REGEXP,
3939
isValidISBN,
40+
ISSN_REGEXP,
4041
} from '../../../../constants'
4142
import {
4243
Contributor,
@@ -258,6 +259,17 @@ export class WorkFormComponent implements OnInit {
258259
}
259260
}
260261

262+
if (externalIdentifierType === 'issn') {
263+
if (!ISSN_REGEXP.test(control.value)) {
264+
control.markAsTouched()
265+
return of({
266+
validFormat: true,
267+
resolved: false,
268+
attemptedResolution: false,
269+
})
270+
}
271+
}
272+
261273
return this._workService
262274
.validateWorkIdTypes(externalIdentifierType, control.value)
263275
.pipe(

0 commit comments

Comments
 (0)