Content deleted Content added
m oclc to 10 digit max; |
Synch from sandbox; |
||
Line 1:
local identifiers = {};
Line 97 ⟶ 98:
local function check_isbn( isbn_str )
if nil ~= isbn_str:match("[^%s-0-9X]") then
return false end
isbn_str = isbn_str:gsub( "-", "" ):gsub( " ", "" ); -- remove hyphens and spaces
local len = isbn_str:len();
if len ~= 10 and len ~= 13 then
return false, 'length'; -- fail if incorrect length
end
if len == 10 then
if isbn_str:match( "^%d*X?$" ) == nil then --
return
end
return is_valid_isxn(isbn_str, 10), 'checksum';
else
if isbn_str:match( "^%d+$" ) == nil then
local temp = 0;▼
return false, 'invalid character'; -- fail if isbn13 is not all digits
end
return is_valid_isxn_13 (isbn_str);▼
if isbn_str:match( "^97[89]%d*$" ) == nil then
return false, 'invalid prefix'; -- fail when isbn13 does not begin with 978 or 979
end
▲ return is_valid_isxn_13 (isbn_str), 'checksum';
end
end
Line 723 ⟶ 732:
elseif k == 'ISBN' then
local ISBN = internal_link_id( handler );
local check;
if not check_isbn( v ) and not is_set(options.IgnoreISBN) then▼
ISBN = ISBN .. set_error( 'bad_isbn', {}, false, " ", "" );▼
▲-- if not check_isbn( v ) and not is_set(options.IgnoreISBN) then
▲-- ISBN = ISBN .. set_error( 'bad_isbn', {}, false, " ", "" );
-- end
check, err_type = check_isbn( v );
if not check then
if is_set(options.IgnoreISBN) then -- ISBN is invalid; if |ignore-isbn-error= set
add_maint_cat ('ignore_isbn_err'); -- ad a maint category
else
ISBN = ISBN .. set_error( 'bad_isbn', {err_type}, false, " ", "" ); -- else display an error message
end
elseif is_set(options.IgnoreISBN) then -- ISBN is OK; if |ignore-isbn-error= set
add_maint_cat ('ignore_isbn_err'); -- because |ignore-isbn-error= unnecessary
end
table.insert( new_list, {handler.label, ISBN } );
|