Unicode: check encoding of files given to configure_file.
UTF-16 and UTF-32 files are rejected.
This commit is contained in:
parent
e21ffaf8fe
commit
98383f802a
|
@ -3518,6 +3518,20 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
|
||||
if(bom != cmsys::FStream::BOM_None &&
|
||||
bom != cmsys::FStream::BOM_UTF8)
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "File starts with a Byte-Order-Mark that is not UTF-8:\n "
|
||||
<< sinfile;
|
||||
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||
return 0;
|
||||
}
|
||||
// rewind to copy BOM to output file
|
||||
fin.seekg(0);
|
||||
|
||||
|
||||
// now copy input to output and expand variables in the
|
||||
// input file at the same time
|
||||
std::string inLine;
|
||||
|
|
|
@ -95,6 +95,7 @@ add_RunCMake_test(TargetPolicies)
|
|||
add_RunCMake_test(alias_targets)
|
||||
add_RunCMake_test(interface_library)
|
||||
add_RunCMake_test(no_install_prefix)
|
||||
add_RunCMake_test(configure_file)
|
||||
|
||||
find_package(Qt4 QUIET)
|
||||
find_package(Qt5Core QUIET)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
configure_file(NO-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/NO-BOM.txt)
|
|
@ -0,0 +1 @@
|
|||
Hello World
|
|
@ -0,0 +1,8 @@
|
|||
include(RunCMake)
|
||||
|
||||
run_cmake(NO-BOM)
|
||||
run_cmake(UTF8-BOM)
|
||||
run_cmake(UTF16LE-BOM)
|
||||
run_cmake(UTF16BE-BOM)
|
||||
run_cmake(UTF32LE-BOM)
|
||||
run_cmake(UTF32BE-BOM)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error at UTF16BE-BOM.cmake:2 \(configure_file\):
|
||||
File starts with a Byte-Order-Mark that is not UTF-8:
|
||||
|
||||
.*/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
configure_file(UTF16BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16BE-BOM.txt)
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error at UTF16LE-BOM.cmake:2 \(configure_file\):
|
||||
File starts with a Byte-Order-Mark that is not UTF-8:
|
||||
|
||||
.*/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
configure_file(UTF16LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16LE-BOM.txt)
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error at UTF32BE-BOM.cmake:2 \(configure_file\):
|
||||
File starts with a Byte-Order-Mark that is not UTF-8:
|
||||
|
||||
.*/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
configure_file(UTF32BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32BE-BOM.txt)
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,6 @@
|
|||
CMake Error at UTF32LE-BOM.cmake:2 \(configure_file\):
|
||||
File starts with a Byte-Order-Mark that is not UTF-8:
|
||||
|
||||
.*/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
configure_file(UTF32LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32LE-BOM.txt)
|
Binary file not shown.
|
@ -0,0 +1,2 @@
|
|||
|
||||
configure_file(UTF8-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF8-BOM.txt)
|
|
@ -0,0 +1 @@
|
|||
Hello World
|
Loading…
Reference in New Issue