浏览代码

优化API文档模板参数格式校验

Karson 4 年之前
父节点
当前提交
ab89d2d506
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      application/admin/command/Api.php

+ 5 - 1
application/admin/command/Api.php

@@ -37,6 +37,10 @@ class Api extends Command
         $force = $input->getOption('force');
         $url = $input->getOption('url');
         $language = $input->getOption('language');
+        $template = $input->getOption('template');
+        if (!preg_match("/^([a-z0-9]+)\.html\$/i", $template)) {
+            throw new Exception('template file not correct');
+        }
         $language = $language ? $language : 'zh-cn';
         $langFile = $apiDir . 'lang' . DS . $language . '.php';
         if (!is_file($langFile)) {
@@ -51,7 +55,7 @@ class Api extends Command
         }
         // 模板文件
         $template_dir = $apiDir . 'template' . DS;
-        $template_file = $template_dir . $input->getOption('template');
+        $template_file = $template_dir . $template;
         if (!is_file($template_file)) {
             throw new Exception('template file not found');
         }