Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Uncaught InvalidArgumentException: und is not a valid language code #2371

Open
aelliott1485 opened this issue Jan 21, 2023 · 0 comments

Comments

@aelliott1485
Copy link
Contributor

Describe the Bug

When attempting to load a file with the XML in the
styles.xml file attached in styles.zip, containing the following XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:styles
	xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:o="urn:schemas-microsoft-com:office:office"
	xmlns:r="http:https://schemas.openxmlformats.org/officeDocument/2006/relationships"
	xmlns:m="http:https://schemas.openxmlformats.org/officeDocument/2006/math"
	xmlns:v="urn:schemas-microsoft-com:vml"
	xmlns:wp="http:https://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
	xmlns:w10="urn:schemas-microsoft-com:office:word"
	xmlns:w="http:https://schemas.openxmlformats.org/wordprocessingml/2006/main"
	xmlns:wne="http:https://schemas.microsoft.com/office/word/2006/wordml"
	xmlns:sl="http:https://schemas.openxmlformats.org/schemaLibrary/2006/main"
	xmlns:a="http:https://schemas.openxmlformats.org/drawingml/2006/main"
	xmlns:pic="http:https://schemas.openxmlformats.org/drawingml/2006/picture"
	xmlns:c="http:https://schemas.openxmlformats.org/drawingml/2006/chart"
	xmlns:lc="http:https://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"
	xmlns:dgm="http:https://schemas.openxmlformats.org/drawingml/2006/diagram"
	xmlns:wps="http:https://schemas.microsoft.com/office/word/2010/wordprocessingShape"
	xmlns:wpg="http:https://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
	xmlns:w14="http:https://schemas.microsoft.com/office/word/2010/wordml"
	xmlns:w15="http:https://schemas.microsoft.com/office/word/2012/wordml">
	<w:docDefaults>
		<w:rPrDefault>
			<w:rPr>
				<w:sz w:val="22"/>
				<w:szCs w:val="22"/>
				<w:lang w:val="en-US"/>
			</w:rPr>
		</w:rPrDefault>
		<w:pPrDefault>
			<w:pPr>
				<w:spacing w:after="200" w:line="276" w:lineRule="auto"/>
			</w:pPr>
		</w:pPrDefault>
	</w:docDefaults>
	<w:style w:type="paragraph" w:styleId="Normal" w:default="1">
		<w:name w:val="normal"/>
	</w:style>
	<w:style w:type="table" w:styleId="TableNormal" w:default="1">
		<w:name w:val="Table Normal"/>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Heading1">
		<w:name w:val="heading 1"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="120" w:before="480" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:b w:val="1"/>
			<w:sz w:val="48"/>
			<w:szCs w:val="48"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Heading2">
		<w:name w:val="heading 2"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="80" w:before="360" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:b w:val="1"/>
			<w:sz w:val="36"/>
			<w:szCs w:val="36"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Heading3">
		<w:name w:val="heading 3"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="80" w:before="280" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:b w:val="1"/>
			<w:sz w:val="28"/>
			<w:szCs w:val="28"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Heading4">
		<w:name w:val="heading 4"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="40" w:before="240" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:b w:val="1"/>
			<w:sz w:val="24"/>
			<w:szCs w:val="24"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Heading5">
		<w:name w:val="heading 5"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="40" w:before="220" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:b w:val="1"/>
			<w:sz w:val="22"/>
			<w:szCs w:val="22"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Heading6">
		<w:name w:val="heading 6"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="40" w:before="200" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:b w:val="1"/>
			<w:sz w:val="20"/>
			<w:szCs w:val="20"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Title">
		<w:name w:val="Title"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="120" w:before="480" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:b w:val="1"/>
			<w:sz w:val="72"/>
			<w:szCs w:val="72"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Normal">
		<w:name w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="0"/>
		<w:pPr>
			<w:suppressAutoHyphens w:val="1"/>
			<w:spacing w:after="200" w:line="276" w:lineRule="auto"/>
			<w:ind w:leftChars="-1" w:rightChars="0" w:firstLineChars="-1"/>
			<w:textDirection w:val="btLr"/>
			<w:textAlignment w:val="top"/>
			<w:outlineLvl w:val="0"/>
		</w:pPr>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:sz w:val="22"/>
			<w:szCs w:val="22"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang w:bidi="ar-SA" w:eastAsia="en-US" w:val="en-US"/>
		</w:rPr>
	</w:style>
	<w:style w:type="character" w:styleId="DefaultParagraphFont">
		<w:name w:val="Default Paragraph Font"/>
		<w:next w:val="DefaultParagraphFont"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="1"/>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang/>
		</w:rPr>
	</w:style>
	<w:style w:type="table" w:styleId="TableNormal">
		<w:name w:val="Table Normal"/>
		<w:next w:val="TableNormal"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="1"/>
		<w:pPr>
			<w:suppressAutoHyphens w:val="1"/>
			<w:spacing w:line="1" w:lineRule="atLeast"/>
			<w:ind w:leftChars="-1" w:rightChars="0" w:firstLineChars="-1"/>
			<w:textDirection w:val="btLr"/>
			<w:textAlignment w:val="top"/>
			<w:outlineLvl w:val="0"/>
		</w:pPr>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang/>
		</w:rPr>
		<w:tblPr>
			<w:tblStyle w:val="TableNormal"/>
			<w:jc w:val="left"/>
			<w:tblCellMar>
				<w:top w:w="0.0" w:type="dxa"/>
				<w:left w:w="108.0" w:type="dxa"/>
				<w:bottom w:w="0.0" w:type="dxa"/>
				<w:right w:w="108.0" w:type="dxa"/>
			</w:tblCellMar>
		</w:tblPr>
	</w:style>
	<w:style w:type="numbering" w:styleId="NoList">
		<w:name w:val="No List"/>
		<w:next w:val="NoList"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="1"/>
		<w:pPr>
			<w:suppressAutoHyphens w:val="1"/>
			<w:spacing w:line="1" w:lineRule="atLeast"/>
			<w:ind w:leftChars="-1" w:rightChars="0" w:firstLineChars="-1"/>
			<w:textDirection w:val="btLr"/>
			<w:textAlignment w:val="top"/>
			<w:outlineLvl w:val="0"/>
		</w:pPr>
	</w:style>
	<w:style w:type="table" w:styleId="TableGrid">
		<w:name w:val="Table Grid"/>
		<w:basedOn w:val="TableNormal"/>
		<w:next w:val="TableGrid"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="0"/>
		<w:pPr>
			<w:suppressAutoHyphens w:val="1"/>
			<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
			<w:ind w:leftChars="-1" w:rightChars="0" w:firstLineChars="-1"/>
			<w:textDirection w:val="btLr"/>
			<w:textAlignment w:val="top"/>
			<w:outlineLvl w:val="0"/>
		</w:pPr>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang/>
		</w:rPr>
		<w:tblPr>
			<w:tblStyle w:val="TableGrid"/>
			<w:jc w:val="left"/>
			<w:tblBorders>
				<w:top w:color="auto" w:space="0" w:sz="4" w:val="single"/>
				<w:left w:color="auto" w:space="0" w:sz="4" w:val="single"/>
				<w:bottom w:color="auto" w:space="0" w:sz="4" w:val="single"/>
				<w:right w:color="auto" w:space="0" w:sz="4" w:val="single"/>
				<w:insideH w:color="auto" w:space="0" w:sz="4" w:val="single"/>
				<w:insideV w:color="auto" w:space="0" w:sz="4" w:val="single"/>
			</w:tblBorders>
		</w:tblPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Header">
		<w:name w:val="Header"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Header"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="1"/>
		<w:pPr>
			<w:tabs>
				<w:tab w:val="center" w:leader="none" w:pos="4153"/>
				<w:tab w:val="right" w:leader="none" w:pos="8306"/>
			</w:tabs>
			<w:suppressAutoHyphens w:val="1"/>
			<w:spacing w:after="200" w:line="276" w:lineRule="auto"/>
			<w:ind w:leftChars="-1" w:rightChars="0" w:firstLineChars="-1"/>
			<w:textDirection w:val="btLr"/>
			<w:textAlignment w:val="top"/>
			<w:outlineLvl w:val="0"/>
		</w:pPr>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:sz w:val="20"/>
			<w:szCs w:val="20"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang w:bidi="ar-SA" w:eastAsia="en-US" w:val="und"/>
		</w:rPr>
	</w:style>
	<w:style w:type="character" w:styleId="HeaderChar">
		<w:name w:val="Header Char"/>
		<w:next w:val="HeaderChar"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="0"/>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang w:eastAsia="en-US"/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Footer">
		<w:name w:val="Footer"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Footer"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="1"/>
		<w:pPr>
			<w:tabs>
				<w:tab w:val="center" w:leader="none" w:pos="4153"/>
				<w:tab w:val="right" w:leader="none" w:pos="8306"/>
			</w:tabs>
			<w:suppressAutoHyphens w:val="1"/>
			<w:spacing w:after="200" w:line="276" w:lineRule="auto"/>
			<w:ind w:leftChars="-1" w:rightChars="0" w:firstLineChars="-1"/>
			<w:textDirection w:val="btLr"/>
			<w:textAlignment w:val="top"/>
			<w:outlineLvl w:val="0"/>
		</w:pPr>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:sz w:val="20"/>
			<w:szCs w:val="20"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang w:bidi="ar-SA" w:eastAsia="en-US" w:val="und"/>
		</w:rPr>
	</w:style>
	<w:style w:type="character" w:styleId="FooterChar">
		<w:name w:val="Footer Char"/>
		<w:next w:val="FooterChar"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="0"/>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang w:eastAsia="en-US"/>
		</w:rPr>
	</w:style>
	<w:style w:type="character" w:styleId="Emphasis">
		<w:name w:val="Emphasis"/>
		<w:next w:val="Emphasis"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="0"/>
		<w:rPr>
			<w:i w:val="1"/>
			<w:iCs w:val="1"/>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang/>
		</w:rPr>
	</w:style>
	<w:style w:type="character" w:styleId="Hyperlink">
		<w:name w:val="Hyperlink"/>
		<w:next w:val="Hyperlink"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="1"/>
		<w:rPr>
			<w:color w:val="0000ff"/>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:u w:val="single"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang/>
		</w:rPr>
	</w:style>
	<w:style w:type="character" w:styleId="flagcss">
		<w:name w:val="flagcss"/>
		<w:next w:val="flagcss"/>
		<w:autoRedefine w:val="0"/>
		<w:hidden w:val="0"/>
		<w:qFormat w:val="0"/>
		<w:rPr>
			<w:w w:val="100"/>
			<w:position w:val="-1"/>
			<w:effect w:val="none"/>
			<w:vertAlign w:val="baseline"/>
			<w:cs w:val="0"/>
			<w:em w:val="none"/>
			<w:lang/>
		</w:rPr>
	</w:style>
	<w:style w:type="paragraph" w:styleId="Subtitle">
		<w:name w:val="Subtitle"/>
		<w:basedOn w:val="Normal"/>
		<w:next w:val="Normal"/>
		<w:pPr>
			<w:keepNext w:val="1"/>
			<w:keepLines w:val="1"/>
			<w:pageBreakBefore w:val="0"/>
			<w:spacing w:after="80" w:before="360" w:lineRule="auto"/>
		</w:pPr>
		<w:rPr>
			<w:rFonts w:ascii="Georgia" w:cs="Georgia" w:eastAsia="Georgia" w:hAnsi="Georgia"/>
			<w:i w:val="1"/>
			<w:color w:val="666666"/>
			<w:sz w:val="48"/>
			<w:szCs w:val="48"/>
		</w:rPr>
	</w:style>
	<w:style w:type="table" w:styleId="Table1">
		<w:basedOn w:val="TableNormal"/>
		<w:tblPr>
			<w:tblStyleRowBandSize w:val="1"/>
			<w:tblStyleColBandSize w:val="1"/>
			<w:tblCellMar>
				<w:top w:w="0.0" w:type="dxa"/>
				<w:left w:w="108.0" w:type="dxa"/>
				<w:bottom w:w="0.0" w:type="dxa"/>
				<w:right w:w="108.0" w:type="dxa"/>
			</w:tblCellMar>
		</w:tblPr>
	</w:style>
</w:styles>

note there are two <w:lang> elements under the styles for the header and footer paragraphs with attribute w:val="und"/

<w:lang w:bidi="ar-SA" w:eastAsia="en-US" w:val="und"/>

The following exception is thrown:

Fatal error: Uncaught InvalidArgumentException: und is not a valid language code in phpoffice\phpword\src\PhpWord\Style\Language.php:252

Steps to Reproduce

  1. save the attached DOCX file: fileWithUndLangInHeaderAndFooter.docx to a path e.g. C:\temp or ~/tmp
  2. run the following PHP code:
<?php
require __DIR__ . '/vendor/autoload.php';

$path = 'C:\\temp\\fileWithUndLangInHeaderAndFooter.docx';

$phpWord = \PhpOffice\PhpWord\IOFactory::load($path);

Expected Behavior

The phpword reader object is initialized for reading.

Current Behavior

The exception is thrown:

Fatal error: Uncaught InvalidArgumentException: und is not a valid language code in phpoffice\phpword\src\PhpWord\Style\Language.php:252

full trace:

Uncaught InvalidArgumentException: und is not a valid language code in C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style\Language.php:252
Stack trace:
#0 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style\Language.php(142): PhpOffice\PhpWord\Style\Language->validateLocale('und')
#1 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style\Language.php(122): PhpOffice\PhpWord\Style\Language->setLatin('und')
#2 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style\Font.php(895): PhpOffice\PhpWord\Style\Language->__construct('und')
#3 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style\AbstractStyle.php(180): PhpOffice\PhpWord\Style\Font->setLang('und')
#4 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style\AbstractStyle.php(196): PhpOffice\PhpWord\Style\AbstractStyle->setStyleValue('lang', 'und')
#5 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style.php(203): PhpOffice\PhpWord\Style\AbstractStyle->setStyleByArray(Array)
#6 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Style.php(62): PhpOffice\PhpWord\Style::setStyleValues('Header', Object(PhpOffice\PhpWord\Style\Font), Array)
#7 [internal function]: PhpOffice\PhpWord\Style::addFontStyle('Header', Array, Array)
#8 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\PhpWord.php(144): forward_static_call_array(Array, Array)
#9 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Reader\Word2007\Styles.php(84): PhpOffice\PhpWord\PhpWord->__call('addfontstyle', Array)
#10 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Reader\Word2007.php(98): PhpOffice\PhpWord\Reader\Word2007\Styles->read(Object(PhpOffice\PhpWord\PhpWord))
#11 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\Reader\Word2007.php(75): PhpOffice\PhpWord\Reader\Word2007->readPart(Object(PhpOffice\PhpWord\PhpWord), Array, 'Styles', 'C:\\users\\aellio...', 'word/styles.xml')
#12 C:\Atlas\vendor\phpoffice\phpword\src\PhpWord\IOFactory.php(89): PhpOffice\PhpWord\Reader\Word2007->load('C:\\users\\aellio...')
#13 C:\Atlas\c\tools\testTextExtract.php(19): PhpOffice\PhpWord\IOFactory::load('C:\\users\\aellio...')
#14 {main}

Context

Environment information:

  • PHP Version: 8.1.13
  • PHPWord Version: dev-master 0806448
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant